使用 httpd.conf 从非 www 到 www - // 错误
使用时
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
当我在 httpd.conf 文件中 ,为什么我的网站重定向到 www.example.com// (www.example.com//file.html)。为什么有两个斜杠?
When I use
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
in my httpd.conf file, why is my site redirecting to www.example.com//
(www.example.com//file.html). Why are there two slashes ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这应该是:
编辑:
上面的
RewriteCond
可能有点矫枉过正 - 它的目的是只匹配前面没有www
的网址。然而,这也应该有效:就像 David Chan 提到的那样,
^(.*)$
就是你所缺少的。^
和$
是正则表达式中的特殊字符。以下是解释正则表达式字符串锚点的链接: http://www.regular-expressions.info/anchors .html另外,这里有一个链接可以更详细地解释 mod_rewrite 语法: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
I think this should be:
EDIT:
The above
RewriteCond
was probably overkill - it was intended to only match urls that are not preceded bywww
. However this should work too:Like David Chan mentioned, the
^(.*)$
is what you were missing. The^
and$
are special characters in Regular Expressions. Here is a link that explains regex string anchors: http://www.regular-expressions.info/anchors.htmlAlso, here is a link that can explain the mod_rewrite syntax in more detail: http://httpd.apache.org/docs/current/mod/mod_rewrite.html