如何在保留路径的同时 301 重定向整个域 [英] How to 301 redirect an entire domain while preserving the path
问题描述
我正在将一个域重定向到另一个域,但我想保留重定向中的路径.例如,我想访问 www.example.com/services/education/page.html
,但我的重定向会将它们带到 www.new-example.com/services/education/page.html
.我在我的 .htaccess 文件中写了什么来保留路径/services/education/page.html"?
I am redirecting one domain to another, but I want to preserve the path in the redirect. So for example, I want to visit www.example.com/services/education/page.html
, but my redirect will bring them to www.new-example.com/services/education/page.html
. What do I write in my .htaccess file to preserve the path "/services/education/page.html"?
现在我有:
redirect 301 http://www.example.com/ http://www.new-example.com/
但我不确定这是否有效(由于我正在等待域详细信息等,因此无法进行测试).我只是想确定我何时将网站上线.是这样还是我离基地很远?
But I'm not sure if that works or not (Can't test yet as I am waiting for domain details etc). I just want to be sure when I put the site live. Is that right or am I way off base?
谢谢!
推荐答案
应该这样做:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !new-example.com$ [NC]
RewriteRule ^(.*)$ http://new-example.com/$1 [L,R=301]
这篇关于如何在保留路径的同时 301 重定向整个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!