繁体   English   中英

.htaccess 301重定向无法正常工作?

[英].htaccess 301 redirect not working?

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

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

编辑:

它可能不是必需的信息,但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规则。
  2. 在默认WP规则之前保留重定向规则。

使用此DocumentRoot/.htaccesswordpress目录上方一级 ):

RewriteEngine On

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

并从Wordpress .htaccess中删除Redirect指令。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM