即使请求的文件存在,.htaccess也会将所有请求重定向到index.php

时间:2013-06-24 10:32:12

标签: .htaccess url rewrite

我正在写第一个 .htaccess 文件。我想知道即使“localhost/home/user/”目录存在,如何将localhost/index.php?home&id=user重写为home

这可能吗?

1 个答案:

答案 0 :(得分:1)

这样做很糟糕,但是,如果你真的想要这个,你需要的是:

RewriteEngine On
RewriteBase /

#(things you want to do beforehand)

RewriteCond %{HTTP_REFERER} !^$
RewriteRule !^http://localhost/index.php?home&id=user [R,L]
#(things you want to do after redirect)

(根据您使用的安全性,您可能需要localhost而不是'user';如果使用Apache的.htpasswd,则可能需要来自PHP的$1 您可以添加不同的标志,RewriteRule标志文档是here