的.htaccess 301重定向不工作? [英] .htaccess 301 redirect not working?

查看:183
本文介绍了的.htaccess 301重定向不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有形式page1.html的静态页面在我的根目录和另一页的index.php也在根目录中。我所要做的是将所有旧的导入链接指向一个字preSS目录。我得到通过的.htaccess而我从我的托管服务提供商帮助网站找到了index.php文件重定向到主域名(即abc.com现在重定向到我的话preSS安装文件夹正确)。

我现在已经是,这直接关系到或索引的页面仍然显示的问题。例如abc.com/page1.html仍是可见的。我试着用以下的.htaccess code重定向到新网站:

 重定向301 /page1.html abc.com/index.php

以上code应该从我的理解正确的,因为我的index.php负荷高达字preSS数据(使用同样的方法在正常工作abc.com重定向),但由于某种原因重定向是没有发生。

下面是我的.htaccess文件的总体布局。

 #开头的字preSS重定向
#这部分是为abc.com - >字preSS文件夹重定向。
#code从我的托管服务提供商的帮助教程采取海峡。
< IfModule mod_rewrite.c>
RewriteEngine叙述在
的RewriteBase /字pressInstallation /
重写规则^指数\\ $的.php - [L]
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。 /Word$p$pssInstallation/index.php [L]
< / IfModule>下面的问题#code
#静态页面重定向
重定向301 /page1.html的index.php
301重定向的index.php了/page2.html



这是我在做什么错误或我如何能实现我找结果中的任何想法?

编辑:

这可能不是必要的信息,但page1.html,page2.html等文件位于根目录下的.htaccess文件,而这个词preSS安装在一个文件夹命名字pressInstallation在根目录中。我只是想我要澄清的是,如果这个问题没有说清楚。

  /
---字pressInstallation
------字preSS文件(head.php,的index.php,style.css文件等)
--- page1.html
--- page2.html



---的index.php
---的.htaccess




解决方案

  1. 请不要混用的mod_rewrite 规则和 mod_alias中规则。

  2. 保持默认重定向规则WP之前的规则。

使用此的DocumentRoot /的.htaccess 上一层字preSS目录

  RewriteEngine叙述在重写规则^(第1页|第2页)。?\\ HTML $ /字pressInstallation / [L,NC,R = 301]

和从您的Word preSS的.htaccess删除重定向指令。

I have a static page of the form page1.html in my root directory and another page index.php also in the root directory. What I am trying to do is move all old incoming links to point to a wordpress directory. I got the main domain to redirect via the .htaccess and the index.php which I found from my hosting providers help site (i.e. abc.com now redirects to my wordpress installation folder properly).

The problem I have now is, any pages that were directly linked to or indexed are still showing up. For example abc.com/page1.html is still visible. I tried using the following .htaccess code to redirect to the new site:

redirect 301 /page1.html abc.com/index.php

The above code should be correct from my understanding as my index.php loads up the wordpress data (same method used for the correctly working abc.com redirect), but for some reason the redirect is not taking place.

Here is the general layout of my .htaccess file.

# 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
.
.
.

Any ideas on what I am doing wrong or how I can achieve the result I am looking for?

Edit:

It may not be necessary information, but the page1.html, page2.html, etc files are located in the root directory with the .htaccess file while the wordpress installation is in a folder named wordpressInstallation in the root directory. I just thought I would clarify that if the question didn't make that clear.

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

解决方案

  1. Don't mix mod_rewrite rules and mod_alias rules.
  2. Keep redirect rules before default WP rule.

Use this DocumentRoot/.htaccess (one level above wordpress directory):

RewriteEngine On

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

And remove Redirect directives from your Wordpress .htaccess.

这篇关于的.htaccess 301重定向不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆