2个域上的相同重定向规则

时间:2012-09-13 09:22:26

标签: apache .htaccess redirect

我在同一个虚拟主机上运行了2个域

<VirtualHost *:80> 
    ServerName www.example.de
    ServerAlias www.example.de example.de example.co.uk www.example.co.uk
    DocumentRoot C:/inetpub/wwwroot/example_ml
    DirectoryIndex index.php
</VirtualHost>

并尝试在我的htaccess中为两个域应用相同的重定向规则

RewriteRule ^tag/(.*)$ http://www.example.de/$1 [L,R=301]
RewriteRule ^\d{4}/\d{2}/\d{2}/(.*)$ http://www.example.de/$1 [L,R=301]
RewriteRule ^\d{4}/\d{2}/(.*)$ http://www.example.de/$1 [L,R=301]

RewriteRule ^tag/(.*)$ http://www.example.co.uk/$1 [L,R=301]
RewriteRule ^\d{4}/\d{2}/\d{2}/(.*)$ http://www.example.co.uk/$1 [L,R=301]
RewriteRule ^\d{4}/\d{2}/(.*)$ http://www.example.co.uk/$1 [L,R=301]

但似乎不起作用 每个example.co.uk/tag_name我都被重定向到example.de/tag_name

1 个答案:

答案 0 :(得分:0)

您无需定义规则两次,请尝试以下操作:

RewriteRule ^tag/(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
RewriteRule ^\d{4}/\d{2}/\d{2}/(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
RewriteRule ^\d{4}/\d{2}/(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]