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

.htaccess将所有请求重定向到index.php,即使请求的文件存在,.htaccess,url,rewrite,.htaccess,Url,Rewrite,我正在写我的第一个.htaccess文件。我想知道如何将localhost/home/user/重写为localhost/index.php?home&id=user,即使存在“home”目录 这可能吗 这样做是不好的做法,但是,如果你真的想要这样做,你需要的是: RewriteEngine On RewriteBase / #(things you want to do beforehand) RewriteCond %{HTTP_REFERER} !^$ RewriteRule !^ht

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


这可能吗

这样做是不好的做法,但是,如果你真的想要这样做,你需要的是:

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)
(您可能需要
$1
而不是'user',这取决于您使用的安全性;如果使用Apache中的.htpasswd,则需要
$\u服务器['PHP\u AUTH\u user']]
来自PHP)

当然,您可以添加不同的标志,重写规则标志文档是。

您的意思不是相反吗?比如从localhost/home/user到localhost/index.php?home&id=user?否则,您可以使用PHPsry简单地执行此操作。。。是的,我的意思是……不客气(也请用a+1来爱我,不要只把我的答案标为答案!:P)