您在上面发布的规则已经存在于 HTML5 样板的 .htaccess 中(在标题下# Built-in filename-based cache busting
)
# Uncomment to enable.
# <IfModule mod_rewrite.c>
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
# </IfModule>
您可以通过删除每行开头的“#”来取消注释它们。并更改第 5 行以允许您对 favicon.ico 的规则:
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif|ico)$ $1.$3 [L]
编辑:要将所有请求定向到 index.php,我# Suppress or force the "www." at the beginning of URLs
以这种方式修改了规则:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !^(.+)\.(js|css|png|jpg|gif|ico)$
RewriteRule ^(.*)$ index.php [NC]
</IfModule>
一般来说,您应该将自己的规则放在 .htaccess 文件的开头,放在其他规则之前,而不是在这些规则之后。