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/$1
This htaccess isn’t limited to use in WordPress alone and should work for Joomla, Drupal or any Website hosted on Apache HTTP Server.
Hi, the name of my subfolder and subdomain is not the same, the redirect will lead me an empty subdomain page. Ex. I want http://www.mysite.com/community to become http://www.forums.dipolog.com. How can I achieve that when i go to http://www.forums.dipolog.com it will show all the contents inside the /community wihtou renaming the /community folder?
Hello and thank you for this piece of code.
I had a problem though, with redirection from yourdomain.com to http://www.yourdomain.com
When I entered yourdomain.com/subfolder, I got redirected to yourdomain.comsubfolder.
After adding in a slash at line 4 after example.com, It worked for me. The whole thing then lookes like this:
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/$1
Cheers
Gerhard,
can you please code this for any subfolder to wildcard(any) subdomain.
This was very helpful. I was able to quickly rewrite a subdomain to a domain.
Thank you, it works!
I have a website gb.idsrealestate.com that is not displaying the CSS. The website is a sub domain website with a subfolder (wp). I am trying to display the website properly.
I tried using the code provided but am not sure how to properly implement.
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/$1
Site: gb.idsrealestate.com
Sub Folder: /wp/ –> all WordPress files location
Doesn’t work for me at all.
It changed domain.com/sub –> sub.domain.com
BUT the directory that seems to appear is the root directory. So I’ve remapped the subdomain to the root… which is pointless.