Mod_rewrite无法静默重定向


Mod_rewrite failing to silently redirect

经过两天的挣扎,头发少了一磅,我想是时候寻求帮助了。我最近将我的项目迁移到了一个主子目录中,因此结构如下:

-application/
   -index.php
   -signup/
      -index.php
      -signup_set.php
-css/
-js/

我一直在尝试让mod_rewrite为我做工作,从所有url中排除"application/"。这是我的根目录。htaccess:

RewriteEngine On 
#first round through, prepend 'application/' to request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !^application
RewriteRule ^(.*)$ application/$1 [L]
#second round through, if the new url is not directory or file, append .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L] 

我可能对regex/mod_rewrite有一个糟糕的理解,但这似乎部分有效。一定程度上奇怪的是,当我路由到一个"漂亮的url"(例如www/signup)时,顶部栏中的url会被物理重写,以包括"application/"(例如www/application/signup)。所以不知怎么的,这个"无声"的重写过程变得相当响亮。。。有什么建议吗?我意识到我可以更改根目录,但这需要重写引用css/js文件的代码。我比任何事情都好奇,只是试着找到一些机会。任何帮助都将不胜感激!谢谢StackOverflow,你太棒了。

附言:我在Windows7上运行Apache,并使用虚拟主机(如果其中任何一个相关)

下面的规则适用于我在Windows 7上使用虚拟主机运行Apache。我所改变的只是第二个RewriteCond

RewriteEngine On
# Append trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(?:'.'w+|/)$
RewriteRule ^(.*)$ /$1/ [L]
# First round through, prepend 'application/' to request
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/application
RewriteRule ^(.*)$ application/$1 [L]
# Second round through, if the new url is not directory or file, append .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !'.'w+$
RewriteRule ^(.*)/$ $1.php [L]