Redirecting A WordPress Blog From A Directory To The Root

by Darren McLaughlin

December 22, 2008 – 4:27 pm

Problem - You have an old blog in a directory and would like to move it to the domain, replacing your website’s content at the root.

Solution: use mod_alias redirectmatch

Scenario one, you move a blog from /blog/ to the root. Here’s the example code.


RedirectMatch 301 ^/blog/(.*)/(.*)/$ http://www.yourdomain.com/$2/

Keep in mind this all needs to be one line in your .htaccess. This line tells Apache to send all trafficked destined for the /blog/ subdirectory, and instead redirect it to the old file name at the root domain.

Problem: You want to remove the dates in the URLs.

Solution: change your permalinks structure to /%postname/ only, and redirect the old requests to the new URLs using redirectmatch.


RedirectMatch 301 ^/(?!category/)(?!tag/)(.*)/(.*)/$ http://www.yourdomain.com/$2/

This time you’ll exclude any pages that begin with “category” or “tag” and rewrite any requests for your old page names to the root of the domain, without the date fields included.

This is beneficial if you want to dump the date structure, which creates even lengthier URLs than needed.

The advantage to use 301 redirection is that you don’t have to notify anyone or any search engine that your permalink structure has changed. The 301 will be read by visitors and search engines alike, any links built to your pages will be automatically, and permanently, updated the next time your website is crawled and indexed.

Tags: ,

Add your thoughts