| Author |
|
user1983 Newbie

Joined: 07 October 2008
Online Status: Offline Posts: 8
|
| Posted: 07 October 2008 at 5:13pm | IP Logged
|
|
|
I've been at this for a while and really need some help. I've tried a few things, but nothing appears to work.
I want to rewrite on two conditions:
1) if the HOST does not match domain.com
2) if the URL is empty
if this is the case, then I want to redirect to HOST/correct.html
Here's what won't work, and I have no idea why:
RewriteCond Host: (?!domain\.com)
RewriteCond URL /
RewriteRule (.*?)(/)? $1/correct.html [I,L]
It appears that my URL condition won't take. ANY help you can give me would be appreciated, because I've been at this for a while now with little to no luck.
|
| Back to Top |
|
| |
user1983 Newbie

Joined: 07 October 2008
Online Status: Offline Posts: 8
|
| Posted: 08 October 2008 at 8:34am | IP Logged
|
|
|
I also gave this a try with no success
RewriteCond Host: (?!domain\.com)
RewriteRule / /correct.html
|
| Back to Top |
|
| |
Lexey Moderator Group

Joined: 15 August 2002 Location: Russian Federation
Online Status: Offline Posts: 7559
|
| Posted: 08 October 2008 at 2:36pm | IP Logged
|
|
|
Try this:
RewriteCond Host: (?!domain\.com)
RewriteRule / /correct.html [I,L]
If it will not work show your test URL, corresponding IIS log record and complete httpd.ini content.
|
| Back to Top |
|
| |
user1983 Newbie

Joined: 07 October 2008
Online Status: Offline Posts: 8
|
| Posted: 10 October 2008 at 9:35am | IP Logged
|
|
|
I found a partial solution Lexey. The problem is that even though I specified that the rule shouldn't apply to domain.com (but to anything else), it still applies to domain.com. I'm wondering whether I'm missing something like a flag? I checked the documentation for 2.x and my syntax looks correct, and I also searched previous forum posts but couldn't find anything like this.
Code:
[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 240
RepeatLimit 32
# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:\.ini|\.parse\.errors).* / [F,I,O]
# Block external access to the Helper ISAPI Extension
RewriteRule .*\.isrwhlp / [F,I,O]
# Redirect sites if there is no URL
RewriteCond Host: (?!domain\.com).* [NC]
RewriteCond URL /
RewriteRule / /correct.html [I,L]
|
|
|
There are other lines below this, but they are very specific and completely unrelated.
|
| Back to Top |
|
| |
Lexey Moderator Group

Joined: 15 August 2002 Location: Russian Federation
Online Status: Offline Posts: 7559
|
| Posted: 14 October 2008 at 1:04pm | IP Logged
|
|
|
Ops, I have forgotten .* in the first condition. And your condition does not work due to [NC].
Correct rule is:
RewriteCond Host: (?!domain\.com).*
RewriteRule / /correct.html [I,L]
|
| Back to Top |
|
| |
user1983 Newbie

Joined: 07 October 2008
Online Status: Offline Posts: 8
|
| Posted: 15 October 2008 at 8:17am | IP Logged
|
|
|
Hi Lexey,
It works!! I just noticed from the 2.x documentation that [NC] does not in fact exist and was only introduced in 3.x, which probably contributed to the problem. However, can you tell me why the "RewriteCond URL /" is not required?
One additional question is, can I add more domains to NOT match against like:
Code:
RewriteCond Host: (?!domain\.com).*
RewriteCond Host: (?!domain1\.com).*
RewriteCond Host: (?!domain2\.com).*
RewriteCond Host: (?!domain3\.com).*
RewriteRule / /correct.html [I,L]
|
|
|
I'm currently testing the above change in a staging environment where we only have 1 such URL, but our production environment will have multiple URLs for which we don't want the rule to work.
Thanks,
|
| Back to Top |
|
| |
Lexey Moderator Group

Joined: 15 August 2002 Location: Russian Federation
Online Status: Offline Posts: 7559
|
| Posted: 15 October 2008 at 1:12pm | IP Logged
|
|
|
Quote:
| However, can you tell me why the "RewriteCond URL /" is not required? |
|
|
RewriteRule / /correct\.html already has this condition implied. So, your condition is simply redudant.
Quote:
| One additional question is, can I add more domains to NOT match against like: |
|
|
Better to do that in the following way:
RewriteCond Host: (?!(?:domain|domain1|domain2|domain3)\.com).*
RewriteRule / /correct.html [I,L]
|
| Back to Top |
|
| |