Apache 将目录重定向到根目录

Apache 将目录重定向到根目录,apache,mod-rewrite,Apache,Mod Rewrite,我的根目录中有一个名为“user”的目录。现在我想将“user”重写为root,这样就可以像下面这样访问例如/user/account.php www.mydomain.com/account.php 我找到了一个类似问题的例子,并根据我的需要对其进行了修改,但是,它并没有按预期工作 RewriteEngine On RewriteRule /user/(.*) /$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_

我的根目录中有一个名为“user”的目录。现在我想将“user”重写为root,这样就可以像下面这样访问例如/user/account.php www.mydomain.com/account.php

我找到了一个类似问题的例子,并根据我的需要对其进行了修改,但是,它并没有按预期工作

RewriteEngine On 
RewriteRule /user/(.*) /$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
两者

www.mydomain.com/account.php

www.mydomain.com/user/account.php

将我重定向到root,而不是转到account.php页面…

行中

RewriteRule /user/(.*) /$1 [L]
尝试用^user/(.*)$替换
/user/(.*)$
另外,$1会将yourdomain.com/user/whatever重定向到yourdomain.com/whatever

那就写吧

RewriteRule ^user/account.php / [L]
或者如果您只有account.php和user account.php 你可以用这条线代替

RewriteRule ^account.php / [L]
这将使每个以account.php结尾的URL重定向到/


希望这一条有帮助。

您可能在account.php脚本中有重定向代码吗?我没有。我还尝试了“users”中的其他文件,结果相同。好的,^user/(.*)$导致“未找到文件”-错误,因此我使用了^/user/(.*)$规则现在是“RewriteRule^/uc/(.*)$/[L]”。我可以访问www.mydomain.com/user/account.php,但它不会重写任何内容。www.mydomain.com/account.php是一个“未找到文件”…您是否启用了mod_重写?您的配置中是否有
AllowOverride All
,以便您可以使用.htaccess?我启用了mod_rewrite。实际上,我正在使用XAMPP,我开始认为这可能是一种缓存问题。我刚刚重置了我的.htaccess文件,但它仍在不断重定向我。。。