Question

I set up my Wordpress website, imported all blog post and submitted my sitemap to Google last month.

I realized that my blog posts appear like: www.domain.com/blog-post-name <- without the /blog/ directory. I can add the blog directory by changing the Wordpress permalinks, but then when someone goes to the old blog URL, they get a 404 error.

Is it possible to direct users who go to www.domain.com/blog-post-name to www.domain.com/blog/blog-post-name

Thanks

Was it helpful?

Solution

This should work for you (changing the www.domain.com to your domain) :

Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_URI} !^/blog/

# Don't apply to URLs that go to existing files or folders
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /blog
RewriteRule ^(.*)$ http://www.domain.com/blog/$1 [L,R=301]

EDIT: This will rewrite specific urls:

RewriteEngine On
RewriteRule ^blog-post1$ http://www.example.com/blog/blog-post1 [R=301,L]
RewriteRule ^blog-post2$ http://www.example.com/blog/blog-post2 [R=301,L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top