【问题标题】:Avoiding Wordpress .htaccess rules on specific folder避免特定文件夹上的 Wordpress .htaccess 规则
【发布时间】:2013-07-15 17:23:27
【问题描述】:

我在根目录和一个与 Wordpress 无关的特定文件夹中安装了 Wordpress。我为特定文件夹创建了一个 .htaccess 文件,但它不起作用。 Wordpress .htaccess 总是被调用。

Wordpress .htaccess:

# BEGIN WordPress
#<IfModule mod_rewrite.c>
#RewriteEngine On
#RewriteBase /
#RewriteRule ^index\.php$ - [L]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]
#</IfModule>
# END WordPress

特定文件夹 .htaccess:

//301 Redirect Old File
Redirect 301 http://www.domain.com/folder/start.php http://www.domain.com/folder/index.php

当我加载上述旧地址(不存在)时,会调用 Wordpress .htaccess,而不是使用文件夹的 .htaccess 进行重定向。

【问题讨论】:

    标签: wordpress .htaccess


    【解决方案1】:

    你不需要多个.htaccess你可以把所有规则放在WordPress主.htaccess上:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !^folder
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress
    

    使用任一:

    RewriteRule ^folder/start\.php$ /folder/index.php [R=301,L,NC]
    

    或者

    Redirect 301 /folder/start.php http://www.domain.com/folder/index.php
    

    不要忘记将folder 更改为您的实际文件夹名称。

    【讨论】:

    • 好的。感谢您的解释,但没有发生 301 重定向。它正在重定向到 404 页面。路径是对的。 :-/
    • 两个文件是否在同一个文件夹中?还是不同的文件夹?
    • start.php 不再存在。 index.php 在文件夹中。 .htaccess 在根目录中。
    • @MarioLimaCavalcanti 您是否尝试过直接访问http://www.domain.com/folder/index.php 并且有效?您还注意到我在上面的答案中为您的 WordPress 规则添加了一个额外的规则吗?
    • 是的,domain.com/folder/index.php 正在工作。我添加了额外的规则,但仍然得到 404。我知道 start.php 不存在,但 .htaccess 应该进行重定向,而不是显示 404 页面。
    猜你喜欢
    • 2014-08-27
    • 2019-09-18
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 2010-12-19
    • 2021-06-19
    • 2012-12-08
    • 1970-01-01
    相关资源
    最近更新 更多