How to Redirect a Subfolder to Subdomain with htaccess
I recently had the need to move a WordPress Website from a subfolder on Godaddy hosting to a subdomain on Hostgator hosting. I used Backupbuddy to move the Site but the Site wasn’t displaying correctly i.e. it looked like the style.css files wasn’t being read.
I installed the Search and Replace Plugin to change any remaining subfolder URLs to the Subdomain URL i.e. changed http://example.com/subfolder to http://subdomain.example.com but still the stylesheet wasn’t being read. Fortunately I found the answer on Shi Chuan’s Blog.
Here then is the htaccess needed to redirect (and rewrite) a subfolder to a subdomain (just replace the words example, subfolder and subdomain where appropriate):
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]
RedirectMatch 301 ^/subfolder/(.*)$ http://subdomain.example.com/$1This htaccess isn’t limited to use in WordPress alone and should work for Joomla, Drupal or any Website hosted on Apache HTTP Server.



