php – 如何强制.htaccess用于路由不路由.css,.js,.jpg等文件?
发布时间:2020-12-13 13:13:42 所属栏目:PHP教程 来源:网络整理
导读:我在网站的子目录中有以下.htaccess文件,它允许我将所有的URL路由到index.php,在这里我可以解析它们. 但是,它不允许我需要的网站的标准文件,例如css,javascript,png等 我需要改变什么(我假设在第四行)允许这些文件,以便他们不被路由到index.php? RewriteEng
我在网站的子目录中有以下.htaccess文件,它允许我将所有的URL路由到index.php,在这里我可以解析它们.
但是,它不允许我需要的网站的标准文件,例如css,javascript,png等 我需要改变什么(我假设在第四行)允许这些文件,以便他们不被路由到index.php? RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond $1 !^(index.php|public|css|js|png|jpg|gif|robots.txt) RewriteRule ^(.*)$index.php/params=$1 [L,QSA] ErrorDocument 404 /index.php
我注意到了您正在使用正斜杠而不是问号… params重定向通常如下所示:
RewriteRule ^(.*)$index.php?params=$1 [L,QSA] 这应该是自己工作的,因为任何这些文件*应该是真实的文件. ErrorDocument 404 /index.php RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$index.php?params=$1 [L,QSA] 要使站点忽略特定的扩展,您可以添加一个条件来忽略大小写,只能检查请求中文件名的结尾: RewriteEngine On RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$[NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$index.php?params=$1 [L,QSA] 如果你想忽略一个文件夹,那么你可以添加: RewriteEngine On RewriteCond %{REQUEST_URI} !(public|css) RewriteCond %{REQUEST_URI} !(.css|.js|.png|.jpg|.gif|robots.txt)$[NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$index.php?params=$1 [L,QSA] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |