I had a WordPress site that I moved folders - http://example.com to http://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/?

  • 1
    Do you have any other content in the root directory other than the blog? Is there anything else that the rule would have to be careful not to redirect? Oct 14, 2016 at 14:44
  • 2
    @StephenOstermiller unfortunately yes - index.php, about.php for example and css folders.
    – movecx
    Oct 14, 2016 at 15:57
  • 1
    Does index.php use rewrite rules to handle many URLs (like WordPress does) or is it just the single URL? Oct 14, 2016 at 15:58
  • 2
    @StephenOstermiller just the single URL
    – movecx
    Oct 14, 2016 at 16:32

1 Answer 1


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.

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.