【发布时间】:2023-03-25 18:44:01
【问题描述】:
我在 .htaceess 中有这段代码:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule aa/(.+) $1 [QSA,L]
RewriteRule .+ index.php?username=$0 [L,QSA]
index.php 内容:
<?php
var_dump($_GET);
?>
这是文件的结构:
root
|
|_____css
| |____ style.css
|
|_____ .htaccess
|_____ index.php
我希望当类型 http://domain/aa/css/style.css 重定向到 /css/style.css 对于我输入的所有其他网址,即:http://domain/test 重定向到 /index.php?username=test
现在当我输入 http://domain/test 时,它的效果很好。但是当我输入 http://domain/aa/css/style.css 而不是 style.css 时,浏览器会显示:
array(1) { ["username"]=> string(13) "css/style.css" }
现在如何将 .htaccess 更改为一切正常?
【问题讨论】:
-
在第二个重写规则之前添加 RewriteCond : RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .+ index.php?username=$0 [L,QSA]
标签: .htaccess mod-rewrite