如何将旧网址重定向到新网址(root->子目录)?

时间:2017-01-20 11:53:28

标签: .htaccess redirect

域根目录上有一个网站:example.com

然后我不得不把它移到example.com/new

我想要做的是将所有旧网址重定向到新网址,而不是根网域(example.com)本身。我的意思是,如果访问者访问example.com,则不应该重定向,但如果他访问了例如example.com/login的子页面,则应将其重定向到新的URL(example.com/new)。


以下是这些示例:

example.com/login - > example.com/new/login

example.com/page/about - > example.com/new/page/about

example.com/page/about/contact - > example.com/new/page/about/contact


example.com/new/something不应重定向到example.com/new/new/something


如何使用.htaccess文件执行此操作?

1 个答案:

答案 0 :(得分:1)

您只需使用Redirect 301

Redirect 301 /login.html http://example.com/new/login.html
Redirect 301 /page/about.html http://example.com/new/page/about.html

这些是 永久 重定向。确保它是烫发,而不是你想做的临时重定向。如果是临时重定向,您可以使用Redirect 302

相关问题