301重定向在WordPress中无法通过.htaccess起作用 [英] 301 redirect not working via .htaccess within WordPress

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

问题描述

我正在尝试在WordPress的.htaccess文件中应用两个301重定向,但出现404错误。

I'm trying to apply two 301 re-directs in my .htaccess file within WordPress, but I get a 404 error.

这就是我所拥有的:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

# X-XSS-Protection
<IfModule mod_headers.c>
  Header set X-XSS-Protection "1; mode=block"
</IfModule>

# X-Frame-Options
<IfModule mod_headers.c>
  Header always append X-Frame-Options SAMEORIGIN
</IfModule>

# Security Headers - X-Content-Type: nosniff
<IfModule mod_headers.c>
  Header set X-Content-Type-Options nosniff
</IfModule>

# BEGIN 301 Redirects
Redirect 301 /old-page-name/ https://www.myurl.com/new-page-name/
Redirect 301 /another-old-page/ https://www.myurl.com/another-new-page/
# END 301 Redirects

我在这里做错了什么?我还尝试过将重定向信息放在WordPress设置之上。

What am I doing wrong here? I've also tried putting the re-direct info above the WordPress settings.

推荐答案

规则排序和<$ c的混合带有 mod_alias 重定向指令)的$ c> mod_rewrite 规则会引起问题。

Ordering of rules and mixing of mod_rewrite rules with mod_alias (Redirect directive) will cause problems.

具有如下规则:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^old-page-name(/.*)?$ https://www.myurl.com/new-page-name/ [L,R=301,NC]

RewriteRule ^another-old-page(/.*)?$ https://www.myurl.com/another-new-page/ [L,R=301,NC]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

这篇关于301重定向在WordPress中无法通过.htaccess起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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