Apache RewriteCond%{REQUEST_FILENAME}!-d无效

时间:2014-09-24 09:07:52

标签: apache .htaccess

我的公司网站存在一些问题。我的同事离开了.htaccess这样的文件:

# Files in this directory will override the
# controlled equivalent.

# First, set up URL rewriting
Options +FollowSymLinks
RewriteEngine On

# Forbid access to .htaccess files
RewriteRule ^\.htaccess$ - [F]
RewriteRule ^php\.ini$ - [F]

# This Apache mod_rewrite rule checks to see
# if the requested file exists as either a file
# or a directory, if it doesn't then we rewrite 
# to the respective controlled location (unless
# we're already there!).
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^.*/_control/.*$
RewriteRule ^(.*)$ _control/$1 [L]

一切正常,但大约一周前,我们的mysite.com/admin和404页面开始重定向到托管公司的网站。我进一步调查,似乎问题在于最后四行。根据格雷格在这里的回答:https://stackoverflow.com/a/697980/1933380我把它改为:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^.*/_control/.*$

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ _control/$1 [L]

但它也不起作用。文件夹结构如下所示:

enter image description here

我错过了什么或犯了错误吗?

1 个答案:

答案 0 :(得分:2)

RewriteCond行与逻辑AND组合在一起,因此如果你有2条RewriteRule行,只写两次是有意义的。

我认为一定是这样的:

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_URI} !^/_control/
 RewriteRule ^(.*)$ /_control/$1 [L]