Conditional rules based on folder and/or extension
5 posts
• Page 1 of 1
Conditional rules based on folder and/or extension
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
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
Re: Conditional rules based on folder and/or extension
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]
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]
Re: Conditional rules based on folder and/or extension
Thanks for the quick reply Anton, really appreciate it.
That's done the job nicely.
That's done the job nicely.
Re: Conditional rules based on folder and/or extension
With rule 3:
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
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
Re: Conditional rules based on folder and/or extension
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]
RewriteCond %{HTTP_HOST} ^(.*test.*)$ [NC]
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 8 guests