有多种方法可以执行此操作以及进行各种重定向,以下列出了它们:
301(永久)重定向:将整个站点永久指向另一个URL。这是最常见的重定向类型,在大多数情况下很有用。在此示例中,我们将重定向到“ example.com”域:
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://example.com/
302(临时)重定向:将整个站点指向另一个临时URL。当您拥有临时目标网页并计划在以后再切换回主目标网页时,这对于SEO很有用:
# This allows you to redirect your entire website to any other domain
Redirect 302 / http://example.com/
将index.html重定向到特定的子文件夹:
# This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/
将旧文件重定向到新文件路径:
# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html
重定向到特定的索引页:
# Provide Specific Index Page (Set the default handler)
DirectoryIndex index.html
RewriteEngine on
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
* stackoverflow.com/a/7578810/1066234