我将一个域重定向到另一个域,但是我想保留重定向中的路径。因此,例如,我想访问www.example.com/services/education/page.html
,但是我的重定向会将它们带到www.new-example.com/services/education/page.html
。我如何在.htaccess文件中写什么来保留路径“/services/education/page.html”?
现在我有:
redirect 301 http://www.example.com/ http://www.new-example.com/
但是我不确定是否可行(目前无法测试,因为我正在等待域详细信息等)。我只是想确定我何时将该网站投入使用。是这样吗?还是我离开基地了?
谢谢!
最佳答案
应该这样做:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !new-example.com$ [NC]
RewriteRule ^(.*)$ http://new-example.com/$1 [L,R=301]
关于.htaccess - 如何在保留路径的同时重定向301整个域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8450573/