开发者

.htaccess rewrite between three servers

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:

  1. %{HTTP_HOST} = current domain name. So if accessed http://examplesite.com/test/directory/page.php then %{HTTP_HOST} will have examplesite.com as its value.

  2. No need for leading slash / after ^ (unless rule will be placed in config file and not .htaccess). For example: when accessing http://examplesite.com/test/directory/page.php the RewriteRule will work with test/directory/page.php.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜