301 redirect not working via .htaccess within Word

2019-06-08 08:19发布

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条回答
Melony?
2楼-- · 2019-06-08 09:04

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
查看更多
登录 后发表回答