【发布时间】:2014-02-08 14:58:10
【问题描述】:
我正在尝试将我的网站(如 example.com/anypage)重定向到 www.example.com/anypage
这就是我在 httpd.conf 文件中使用的内容
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [nocase]
RewriteRule ^(.*) http://www.example.com/$1 [last,redirect=301]
这会将页面重定向到www.example.com//anypage
如何删除多余的斜线?
【问题讨论】:
-
mod_rewrite behaves differently when used in per-server/virtualhost and per-directory configuration:“在每个目录的上下文中(即在
.htaccess文件和Directory块中),[...] mod_rewrite 最初比较RewriteRule指令的 URL 路径是已翻译文件名的完整文件系统路径从前面删除了当前目录路径(包括尾部斜杠)。” -
@Gumbo 的意思是我应该使用
http://www.example.com$1作为RewriteRule? -
要么,要么你不应该捕获前导斜线。
标签: url mod-rewrite slash