Php .htaccess 301重定向不工作?

Php .htaccess 301重定向不工作?,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我的根目录中有一个静态页面,格式为page1.html,根目录中还有另一个页面index.php。我试图做的是将所有旧的传入链接移动到wordpress目录。我通过.htaccess和index.php获得了要重定向的主域,这是我在主机提供商帮助网站上找到的(即abc.com现在正确地重定向到我的wordpress安装文件夹) 我现在的问题是,任何直接链接到或索引到的页面仍然会出现。例如,abc.com/page1.html仍然可见。我尝试使用以下.htaccess代码重定向到新站点: redi

我的根目录中有一个静态页面,格式为page1.html,根目录中还有另一个页面index.php。我试图做的是将所有旧的传入链接移动到wordpress目录。我通过.htaccess和index.php获得了要重定向的主域,这是我在主机提供商帮助网站上找到的(即abc.com现在正确地重定向到我的wordpress安装文件夹)

我现在的问题是,任何直接链接到或索引到的页面仍然会出现。例如,abc.com/page1.html仍然可见。我尝试使用以下.htaccess代码重定向到新站点:

redirect 301 /page1.html abc.com/index.php
从我的理解来看,上述代码应该是正确的,因为我的index.php加载了wordpress数据(与正确工作的abc.com重定向使用的方法相同),但由于某种原因,重定向没有发生

这是我的.htaccess文件的总体布局

# BEGIN WordPress redirect
# This part is for the abc.com -> wordpress folder redirect.
# Code taken strait from my hosting provider's help tutorial.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /WordpressInstallation/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /WordpressInstallation/index.php [L]
</IfModule>

# Problem code below
# Static page redirects
redirect 301 /page1.html /index.php
redirect 301 /page2.html /index.php
.
.
.
  • 不要混合使用
    mod_rewrite
    规则和
    mod_alias
    规则
  • 在默认WP规则之前保留重定向规则
  • 使用此
    DocumentRoot/.htaccess
    比wordpress目录高一级):


    然后从Wordpress.htaccess中删除
    重定向
    指令。

    只是在适当的部分更改后尝试了它,但它仍然没有处理abc.com/page1.html重定向。这是
    /Wordpress安装/
    路径中的.htaccess吗?您正在尝试重定向根路径
    /page1.html
    ?刚刚将问题编辑到澄清文件的结构。我的根目录.htaccess文件只有您在更新的答案中提到的两行。我的wordpress.htaccess文件为空。重定向似乎正在发生,但现在似乎我得到了一个以404错误结尾的无限重定向
    index.php
    驻留在哪里?它是在根目录中还是在wordpress目录中?
    /
    ---wordpressInstallation
    ------Wordpress files (head.php, index.php, style.css etc.)
    ---page1.html
    ---page2.html
    .
    .
    .
    ---index.php
    ---.htaccess
    .
    .
    .
    
    RewriteEngine On
    
    RewriteRule ^(page1|page2)\.html?$ /wordpressInstallation/ [L,NC,R=301]