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.
答
规则排序和 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