简体   繁体   English

301重定向在WordPress中无法通过.htaccess起作用

[英]301 redirect not working via .htaccess within WordPress

I'm trying to apply two 301 re-directs in my .htaccess file within WordPress, but I get a 404 error. 我试图在WordPress的.htaccess文件中应用两个301重定向,但出现404错误。

Here's what I have: 这是我所拥有的:

# 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

What am I doing wrong here? 我在这里做错了什么? I've also tried putting the re-direct info above the WordPress settings. 我还尝试过将重定向信息放在WordPress设置上方。

Ordering of rules and mixing of mod_rewrite rules with mod_alias ( Redirect directive) will cause problems. 规则的排序以及将mod_rewrite规则与mod_aliasRedirect指令)混合使用会引起问题。

Have your rules like this: 有这样的规则:

# 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

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

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