Conditional rules based on folder and/or extension

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 6
Joined: 01 Aug 2012, 08:44

Conditional rules based on folder and/or extension

01 Aug 2012, 08:54

Hi,

I believe what I'm trying to achieve isn't that difficult but I can't seem to get the rules working correctly. I'm trying to create rules for the following scenarios:

1) http://www.domain.com/*.php should 301 redirect to http://www.domain.net/*.php

2) http://www.domain.com/docs/*.html should 301 redirect to http://www.domain.net/docs/*.html

3) Any URL on http://www.domain.com that contains the word 'test' in the URL should 301 redirect to the same page on http://www.domain.net

Is anyone able to provide some assistance on the above rules?

Thanks

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Conditional rules based on folder and/or extension

01 Aug 2012, 09:28

Hello,

please try to use the following config:

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*\.php)$ http://www.domain.net/$1 [NC,R=301,L]

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(docs/.*\.html)$ http://www.domain.net/$1 [NC,R=301,L]

RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*test.*)$ http://www.domain.net/$1 [NC,R=301,L]

User avatar
Posts: 6
Joined: 01 Aug 2012, 08:44

Re: Conditional rules based on folder and/or extension

01 Aug 2012, 10:48

Thanks for the quick reply Anton, really appreciate it.

That's done the job nicely.

User avatar
Posts: 6
Joined: 01 Aug 2012, 08:44

Re: Conditional rules based on folder and/or extension

02 Aug 2012, 07:39

With rule 3:
Any URL on http://www.domain.com that contains the word 'test' in the URL should 301 redirect to the same page on http://www.domain.net


how could I update it so it only looked for the word 'test' as part of the domain name and ignored any occurrences elsewhere in the URL? e.g.

test.domain.com should forward as expected
http://www.testdomain.com should forward as expected
http://www.domain.com/test should not forward

Thanks

User avatar
Posts: 6
Joined: 01 Aug 2012, 08:44

Re: Conditional rules based on folder and/or extension

03 Aug 2012, 10:47

Just in case anyone else is looking for a solution to the above - I believe the following condition does the job:

RewriteCond %{HTTP_HOST} ^(.*test.*)$ [NC]

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 8 guests