两个域名一个站点.htaccess重写

时间:2014-09-09 09:02:37

标签: regex apache .htaccess mod-rewrite

我的网站有两个相似的域名。问题在于Google将其编入索引为两个不同的网站。

如何将一个域指向另一个域?

foo.se/example 应该转到 bar.se/example

我在.htaccess中试过这个:

RewriteCond %{HTTP_HOST} ^foo.se
RewriteRule ^(.*)$ http://bar.se/$1 [R=permanent,L]

foo.se/example 只会导致 bar.se (没有子目录)

有什么想法吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

使用%{REQUEST_URI}代替$1

尝试此规则
RewriteCond %{HTTP_HOST} ^foo\.se$ [NC]
RewriteRule ^ http://bar.se%{REQUEST_URI} [R=301,NE,L]