简体   繁体   English

htaccess中的301未重定向

[英]301 in htaccess is not redirecting

I have the htacess file in the root of a WordPress website (http://www.raynauds.org). 我在WordPress网站(http://www.raynauds.org)的根目录中有htacess文件。 I need to redirect all calls to: 我需要将所有呼叫重定向到:

http://www.raynauds.org/?p=2366 http://www.raynauds.org/?p=2366

to: 至:

http://www.raynauds.org/2012/08/11/dr-maureen-mayes-joins-raynauds-association-medical-advisory-board/ http://www.raynauds.org/2012/08/11/dr-maureen-mayes-joins-raynauds-association-medical-advisory-board/

I am running Apache on a Linxus Server. 我在Linxus服务器上运行Apache。 The code below seems to be doing nothing to redirect the request. 下面的代码似乎没有执行任何操作来重定向请求。 What am I doing wrong? 我究竟做错了什么?

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
Redirect 301 /?p=2366 http://www.raynauds.org/2012/08/11/dr-maureen-mayes-joins-raynauds-association-medical-advisory-board/

Rewrite and Redirect are both applied to the URL before looking for the file to be executed. 在查找要执行的文件之前,重写和重定向都应用于URL。

Your RewriteRules both have the [L] flag stating that this will be the last Rule to modify the URL, so the Redirect will not be used for URLs matching one of the RewriteRules. 您的RewriteRules都带有[L]标志,表明这将是修改URL的最后一个规则,因此,该Redirect将不会用于与RewriteRules之一匹配的URL。

As the second RewriteRule will catch all requests your Redirect will not work. 由于第二个RewriteRule将捕获所有请求,因此您的重定向将不起作用。 You can also redirect with a RewriteRule like 您也可以使用RewriteRule进行重定向,例如

RewriteCond %{QUERY_STRING}  p=2366
RewriteRule . http://www.example.com [R=301,L]

Please also look at the available flags in the Manual 另请参阅手册中的可用标志

Of course this rule should go before RewriteCond/RewriteRule lines of Wordpress itself to work. 当然,此规则应在Wordpress本身的RewriteCond / RewriteRule行起作用之前执行。

将您的Redirect 301规则移到RewriteBase语句下面的RewriteBase

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

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