【发布时间】:2011-02-28 22:08:31
【问题描述】:
我正在尝试将example.com(以及example.com/、www.example.com 和www.example.com/)重定向到example.com/subdirectory。我可以使用 HTML 轻松做到这一点,但根据我的阅读,最好使用 Apache 进行 301 重定向。
如何使用 Apache 做到这一点?
【问题讨论】:
标签: apache url url-rewriting
我正在尝试将example.com(以及example.com/、www.example.com 和www.example.com/)重定向到example.com/subdirectory。我可以使用 HTML 轻松做到这一点,但根据我的阅读,最好使用 Apache 进行 301 重定向。
如何使用 Apache 做到这一点?
【问题讨论】:
标签: apache url url-rewriting
如果你想要 301 重定向:
RedirectMatch 301 ^/$ /subdirectory/
【讨论】:
您应该使用带有RewriteRule 关键字的.htaccess 文件。有关如何执行此操作的更多信息,请参阅Apache docs。
【讨论】:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
注意* 这种 .htaccess 重定向方法仅适用于启用了 Apache Mod-Rewrite 模块的 Linux 服务器。
来源:http://www.webconfs.com/how-to-redirect-a-webpage.php
示例用法是
RewriteRule ^/$ http://somewhere.com/directory [R=301,L]
我猜
【讨论】: