Correcting Permalinks After Moving Content From A Subdirectory To Root

Ran into this problem with the blog:

As previously noted, I moved my WordPress install from a subdirectory to the root of my Web site. I tried the “Giving WordPress Its Own Directory” method, but I didn’t trust it, so I decided to go ahead with a physical move of the software to root.

As a result, all permalinks to the 200+ articles in this blog became broken, since the subdirectory /blog/ was part of the permanent path root. This was bad, because Google has all those old links wrong, and so does my YOURLS install.

So, I needed a fix, stat. Thankfully, Apache has the mod_alias module, which does a better job of rewriting URLs from subdirectories to root directory than mod_rewrite does.

I specifically used the RewritePermanent directive, which allows one to specify part of a URL string, and to where URLs containing that string should be directed. In my case, I wanted to direct all URLs that contained the  /blog/ subdirectory to the root of my site. Thus:

<IfModule mod_alias.c>
RedirectPermanent /blog/

The first argument after RedirectPermanent is the part of the URL you want removed. The second argument is the URL to which you want found URLs redirected.

This works far better for me than the handful of mod_rewrite rules I tried to accomplish the same basic task.

Your Web server must have mod_alias installed for this to work. Most shared Web hosts will have installed mod_alias, but some might not, or might only enable it for selected domains, as a lot of rewrites and aliases can cause trouble with search engine rankings. Check with your Web service provider.

A hat tip to julianmatz at for the tip. All links in this post on delicious:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Check out the Commenting Guidelines before commenting, please!
  • Want to share code? Please put it into a GitHub Gist, CodePen or pastebin and link to that in your comment.
  • Just have a line or two of markup? Wrap them in an appropriate SyntaxHighlighter Evolved shortcode for your programming language, please!