如何在保留路径的同时重定向301整个域 [英] How to 301 redirect an entire domain while preserving the path

查看:82
本文介绍了如何在保留路径的同时重定向301整个域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将一个域重定向到另一个域,但是我想保留重定向中的路径。因此,例如,我想访问 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆