0
votes

I have a webpage with a blog at www.example.com/blog, but the permalink structure is www.example.com/blog-post-url. I have blog posts linked from around the web from years ago with a different permalink structure which is www.example.com/blog/blog-post-url.

So what I need to do is redirect all old blog links from /blog/blog-post-url to just /blog-post-url but without actually redirecting the /blog directory (the blog home page url) to the root /.

3
Did you mean, you want to redirect a post to another url or page? Why not try a plugin instead? wordpress.org/plugins/quick-pagepost-redirect-pluginFariz Luqman
I've updated my answerFariz Luqman
Well, technically the posts don't even exists at /blog/blog-post/, but they did years ago, and back links still exist. So I want to redirect: example.com/blog/happy-days ---> example.com/happy-days But while maintaining the home page URL: example.com/blog/ ---> example.com/blogJeff Callahan

3 Answers

1
votes

Try adding to the top of your htaccess file:

RewriteEngine On
RewriteRule ^blog/(.+)$ /$1 [L,R=301]
1
votes

Or you can try to use .htaccess but checking if uri is /blog/blog* and if it is, then just redirect it to /blog* So it should be something like RewriteRule ^/blogs/(.*)$ /$1 or something similar.

0
votes

Try this method.

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^blog/(.*)$ /$1 [L,R=301]
</IfModule>

This will redirect all non-existence folder a.k.a blog posts to a new place (from /blog/blog-posts --> /blog-posts) while not redirecting the existing files and directories inside the /blog folder.

Going to /blog/existing_directories will not redirect to /existing_directories

Put the .htaccess file on the root directory, and that shall only redirect blog posts to the new link.

Hope that helps.