Mobile app version of vmapp.org
Login or Join
Dunderdale272

: 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

@Dunderdale272

Posted in: #301Redirect #Htaccess #Redirects #Seo

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/.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Dunderdale272

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme