.htaccess 301 重定向不起作用?

2023-12-06

我的根目录中有一个 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
.
.
.

关于我做错了什么或如何实现我想要的结果有什么想法吗?

Edit:

它可能不是必要的信息,但 page1.html、page2.html 等文件与 .htaccess 文件一起位于根目录中,而 wordpress 安装位于根目录中名为 wordpressInstallation 的文件夹中。我只是想如果问题没有说清楚的话我会澄清一下。

/
---wordpressInstallation
------Wordpress files (head.php, index.php, style.css etc.)
---page1.html
---page2.html
.
.
.
---index.php
---.htaccess
.
.
.

  1. 不要混合mod_rewrite规则和mod_alias rules.
  2. 将重定向规则保留在默认 WP 规则之前。

用这个DocumentRoot/.htaccess (WordPress 目录上一级):

RewriteEngine On

RewriteRule ^(page1|page2)\.html?$ /wordpressInstallation/ [L,NC,R=301]

并删除Redirect来自 Wordpress .htaccess 的指令。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

.htaccess 301 重定向不起作用? 的相关文章

随机推荐