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

2023-12-31

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

这是我所拥有的:

# 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 设置之上。


规则的排序和混合mod_rewrite规则与mod_alias (Redirect指令)会导致问题。

你的规则是这样的:

# 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

301 重定向在 WordPress 中无法通过 .htaccess 工作 的相关文章

随机推荐