【问题标题】:Exclude a specific file from htaccess rewrite rules从 htaccess 重写规则中排除特定文件
【发布时间】:2013-02-10 16:30:48
【问题描述】:

我的根目录中安装了 WordPress,它的 htaccess 重写规则阻止我访问 example.com/file.php,而是重定向到 /

我想从重写规则中排除那个特定文件。

现有的 htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]

【问题讨论】:

    标签: php wordpress .htaccess


    【解决方案1】:

    你需要添加

    RewriteCond $1 !^(file\.php)
    

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
    RewriteCond $1 !^(file\.php) [L]
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    【讨论】:

    • 试试我编辑的答案。如果这不起作用 - 尝试将 /index.php 更改为 index.php (即删除 / )
    • 不行。我以不同的顺序移动了file.php 行,有无前置的index.php 斜线。还有其他想法吗?
    • 另一个编辑 - 尝试添加 [L]。如果没有 - 尝试删除除我最后两行之外的所有内容,这行得通吗?如果是这样,请慢慢添加每条额外的行,并查看哪一行停止它。
    • RewriteCond $1 !^(file\.php) [L] 在每个 URL 上抛出 500。 RewriteCond $1 !^(file\.php) 无效。我也尝试了几乎所有我能想到的组合。明白我为什么讨厌 htaccess 了吗?
    猜你喜欢
    • 1970-01-01
    • 2010-12-22
    • 2015-03-21
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 2016-12-27
    • 2014-10-27
    相关资源
    最近更新 更多