: 301 redirecting blog links that don't start with `/blog` to the new blog location I had a WordPress site that I moved folders - http://example.com to http://example.com/blog. The problem now is
I had a WordPress site that I moved folders - example.com to example.com/blog.
The problem now is that many sites still link to my old blog links to /blog-post so when users click on them they get a 404. There's roughly about 100 links like these, however they don't all follow the same URL structure.
For example:
/blog-post
/postname
/2016/01/01/post
Is there any way for me to make those links take them to their NEW locations - which would be just prepending /blog/.
More posts by @Dunderdale272
1 Comments
Sorted by latest first Latest Oldest Best
Try the following in your root .htaccess file (using mod_rewrite):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)
RewriteRule !^blog /blog/%1 [R=301,L]
For all URLs that don't start /blog and don't exist as physical files (in the document root, or anywhere for that matter) then 301 redirect to /blog/<whatever>.
Make sure you clear the browser cache if you've previously tested 301s that have failed.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.