我正在写第一个 .htaccess 文件。我想知道即使“localhost/home/user/
”目录存在,如何将localhost/index.php?home&id=user
重写为home
。
这可能吗?
答案 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。