我在.htaccess文件中有这段代码来重写从大写到小写的URL:
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
我的问题是,如何从此规则中排除.js,.css等文件?
我的htaccess也有其他规则:
RewriteEngine on
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
谢谢。
答案 0 :(得分:2)
您可以添加另一个否定RewriteCond
:
RewriteCond %{THE_REQUEST} !\.(css|js|gif|jpe?g|ico|tiff)\s [NC]
RewriteCond %{THE_REQUEST} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
这将重定向所有请求,除非它以这些扩展名结束。