有多种方法可以做到这一点,不同的重定向,我在下面列出它们:
301(永久)重定向:将整个网站永久指向不同的URL。这是最常见的重定向类型,在大多数情况下很有用。在这个例子中,我们将重定向到“example.com”域:
# This allows you to redirect your entire website to any other domain
Redirect 301/http://example.com/
302(临时)重定向:指整个网站到一个不同的临时网址。
# 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]'* http:// stackoverflow.com/a/7578810/1066234 – 2015-10-20 11:10:30
值得指出的是,特别是从SEO角度来看,将多对一重定向到索引/主页通常是一个坏主意。 Google很可能将其视为软404。 – MrWhite 2017-01-07 12:28:10