【问题标题】:Apache RewriteCond %{REQUEST_FILENAME} !-d not workingApache RewriteCond %{REQUEST_FILENAME} !-d 不工作
【发布时间】:2014-09-24 09:07:51
【问题描述】:

我的公司网站有一些问题。我的同事留下了这样的.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 页面开始重定向到托管公司的网站。我进一步调查,似乎问题出在最后四行。根据 Greg 在这里的回答: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]

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

我是否遗漏了什么或犯了错误?

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    RewriteCond 行与逻辑 AND 组合,因此如果您有 2 个 RewriteRule 行,则将它们写入两次才有意义。

    我觉得应该是这样的:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    • 2023-03-18
    • 2012-10-25
    • 2021-12-22
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    相关资源
    最近更新 更多