0

I know this isn't technically a WordPress issue but since it's on a WP project, I'm posting here hoping others have encountered and resolved a similar issue.

I've changed the Blog section of a site I'm working on to News and it all works great, but the one thing I need is for legacy posts using the Blog slug to redirect using the News one. Seems straightforward, I know, which is why I'm scratching my head with this one.

Here's the code I'm using in my .htaccess file (the last rewrite rule being what I added to the file):

# 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]
RewriteRule ^blog/(.*)$ /news/$1 [R=301,L]
</IfModule>
# END WordPress

For some reason, it isn't working and I've done everyone from flushing the cache to deactivating plugins and nada.

Any insight would be greatly appreciated!

2 Answers 2

2

OK, so here's the solution that works for me...

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^blog/(.*) news/$1 [L,R=301]
</IfModule>

# 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

Thanks again to @WebElaine for the input!

0

I usually have more luck when I put any custom redirects above the WP code. Also you need a / before 'blog' in the redirect:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/blog/(.*)$ /news/$1 [R=301,L]
</IfModule>

# 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
1
  • Thanks for the quick response! Argh, I used your suggestion but I still get 404's. Dang.
    – user117406
    Apr 11, 2017 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.