301 redirect not working via .htaccess within WordPress

匿名 (未验证) 提交于 2019-12-03 09:52:54

问题:

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

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.

回答1:

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

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!