I'd like to copy the same htaccess file to three different servers. However I don't want to update the contents each time I do that. How do I make the domain name be detected 'dynamically'?
For example, I have the following:
Redirect 301 /test/directory/page.php http://examplesite.com/original/location.php
This won't work on the other two domains because, obviously, they have different urls.
Should I modify like this:
RewriteRul开发者_开发知识库e ^/test/directory/page.php /original/location.php [R=301,L]
Or is there a better way where I don't have to specify the domain name?
Yes, this will work (with one small change -- see notes):
RewriteRule ^test/directory/page.php /original/location.php [R=301,L]
You can also use this (in case you need to change protocol from current HTTP or HTTPS to a specific one):
RewriteRule ^test/directory/page\.php$ http://%{HTTP_HOST}/original/location.php [R=301,L]
NOTES:
%{HTTP_HOST}
= current domain name. So if accessedhttp://examplesite.com/test/directory/page.php
then%{HTTP_HOST}
will haveexamplesite.com
as its value.No need for leading slash
/
after^
(unless rule will be placed in config file and not .htaccess). For example: when accessinghttp://examplesite.com/test/directory/page.php
theRewriteRule
will work withtest/directory/page.php
.
精彩评论