抱歉标题名称不好...问题是我正在使用标准重写,例如:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
但它也会重写所有包含 html 的文件(如 jquery、css 等)的路径...所以,当我尝试访问时domain.com/templates/js/jquery.min.js
- 我的 php 脚本会抛出异常,因为它没有找到所需的参数。我也尝试添加 [az] 但它没有帮助。
抱歉标题名称不好...问题是我正在使用标准重写,例如:
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
但它也会重写所有包含 html 的文件(如 jquery、css 等)的路径...所以,当我尝试访问时domain.com/templates/js/jquery.min.js
- 我的 php 脚本会抛出异常,因为它没有找到所需的参数。我也尝试添加 [az] 但它没有帮助。
尝试以下操作:
RewriteRule ^([a-z0-9]*)$ index.php?q=$1 [L,QSA]
您需要添加一些条件来排除合法请求:
# if the request isn't for an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# if the request isn't for an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# then rewrite the entire request to index.php
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
由于/templates/js/jquery.min.js
是对现有文件的请求,因此第一个条件将失败并且请求不会被重写为 index.php。