HTML5 Boilerplate .htaccess 重写为index.php
我的问题是:
如果我在 HTML5 Bilerplate 的 .htaccess 文件底部添加以下代码,
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
</IfModule>
这会将所有 REQUEST_URI 发送到我的 index.php,以便我可以处理它们,但它会破坏已定义的 .htaccess 文件中的一些规则多于?如果错了,应该补充什么?
My question is:
if i add the following code at the bottom of .htaccess file of HTML5 Bilerplate
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
</IfModule>
this will send all REQUEST_URI to my index.php so I can handle them but will it break some of the rules from the .htaccess file already defined above? And if its wrong, what should be added?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您上面发布的规则已经存在于 HTML5 样板的 .htaccess 中(在标题
# 内置基于文件名的缓存清除
下)您可以通过删除开头的“#”来取消注释它们每行的。
并更改第 5 行以允许您对 favicon.ico 的规则:
编辑:为了将所有请求定向到 index.php,我修改了
# 禁止或强制“www”下的规则。以这种方式放在 URL 的开头
:通常,您应该将自己的规则放在 .htaccess 文件的开头,位于其他规则之前,而不是之后。
The rules you have posted above are already present in the .htaccess of HTML5 boilerplate (under the heading
# Built-in filename-based cache busting
)You can uncomment them by removing the '#' at the beginning of each line.
And change the 5th line to allow your rule for favicon.ico:
Edit: To direct all requests to index.php, I have modified the rules under
# Suppress or force the "www." at the beginning of URLs
in this way:In general you should put your own rules at the beginning of the .htaccess file before the other rules, not after those.