使用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)。为什么有两个斜线?     
已邀请:
我认为应该是:
RewriteCond %{HTTP_HOST} !^www\\.example\\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
编辑: 上面的
RewriteCond
可能是过分的-旨在仅匹配不以
www
开头的网址。但是,这也应该起作用:
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
就像大卫·陈提到的那样,mentioned5是您所缺少的。
^
$
是正则表达式中的特殊字符。这是解释正则表达式字符串锚点的链接:http://www.regular-expressions.info/anchors.html 另外,这里的链接可以更详细地解释mod_rewrite语法:http://httpd.apache.org/docs/current/mod/mod_rewrite.html     

要回复问题请先登录注册