虚拟主机不会重定向
这是我的虚拟主机文件的剪辑:
SeverName domain.com
ServerAlias www.domain.com
<Directory />
Options -Indexes +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^\./]+\.[^\./]+$ [NC]
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . archive.php [L]
</Directory>
domain.com 不会重定向到 www.domain.com。
不过,下面的部分工作正常,将页面重定向到 archive.php。
Here's a clip of my virtualhost file:
SeverName domain.com
ServerAlias www.domain.com
<Directory />
Options -Indexes +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^\./]+\.[^\./]+$ [NC]
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . archive.php [L]
</Directory>
domain.com doesn't redirect to www.domain.com.
The part below works fine though, redirecting a page to archive.php.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果从匹配模式中删除
/
,该规则是否有效?如果请求是到 http://domain.com 且没有尾随
/
,则规则正如您用前导/
编写的那样,可能不匹配。或者,mod_rewrite 可能会删除前导的/
,因为
上下文中有RewriteBase /
。这就是 RewriteRule 文档(“匹配什么?”)框)似乎在说。Does the rule work if you remove the
/
from the match pattern?If the request is to http://domain.com with no trailing
/
, then the rule as you wrote it with a leading/
might not match. Or, mod_rewrite may remove the leading/
, since you haveRewriteBase /
in a<Directory>
context. This is what the RewriteRule docs ("What is Matched?" box) seem to say.