• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to footer

❤ OrganicWeb

Australian Mailchimp Training Partners

  • Home
  • Services
    • Mailchimp Public Classes
      • Adelaide
      • Auckland
      • Brisbane
      • Melbourne
      • Online
      • Perth
      • Singapore
      • Sydney
      • Wellington
    • Mailchimp Corporate Training
    • Mailchimp Consulting
  • Blog
  • Contact & About
You are here: Home / Internet / How to Redirect a Subfolder to Subdomain with htaccess

How to Redirect a Subfolder to Subdomain with htaccess

January 30, 2012 by Gary 8 Comments

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.

Found this useful? Please share:

  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • More
  • Click to email this to a friend (Opens in new window)

Related

Filed Under: Internet Tagged With: apache, Apache HTTP Server, hosting, how to, htaccess, Redirect, script, URL

Contact Gary now

Email: [email protected] Telephone: (+61) 04 1092 3445

Gary from OrganicWeb
  • This field is for validation purposes and should be left unchanged.

What our clients have to say

Gary totally blew my mind with the possibilities available & how they can work for my business specifically."
Kim, Brisbane
Great facilitator and ensured the whole class was happy and competent at the end of the session."
Natalie, Sydney
Don't waste time looking anywhere else - contact Gary today, you won't be disappointed."
Evelyne, Sydney
He is knowledgeable and gifted on the in's and out's of Mailchimp and email campaigns. I highly recommend him! He will make your efforts count!"
Fred, Melbourne
I highly recommend anyone seeking information on how to use Mailchimp to attend one of Gary's expert workshops."
Beverley, Gold Coast
I was constantly updated by email with progress of the work, which was completed to my total satisfaction. Highly recommendable company."
Harry, London

Learn Mailchimp

Attend one of our classes and learn the tips and tricks to incredible results using Mailchimp
Learn More

Comments

  1. chirro says

    September 3, 2013 at 5:05 pm

    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?

    Reply
  2. Gerhard says

    September 4, 2013 at 2:07 am

    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

    Reply
    • Neeraj Rathod says

      October 8, 2015 at 11:32 pm

      Gerhard,

      can you please code this for any subfolder to wildcard(any) subdomain.

      Reply
  3. CinemaFunk says

    July 12, 2014 at 2:38 am

    This was very helpful. I was able to quickly rewrite a subdomain to a domain.

    Reply
  4. Teuku Ridho says

    September 13, 2015 at 9:56 pm

    Thank you, it works!

    Reply
  5. Andrew Lopez says

    February 27, 2016 at 6:37 am

    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

    Reply
  6. Preston says

    September 19, 2016 at 3:41 am

    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.

    Reply

Leave a Reply Cancel reply

Want Mailchimp Training?

Gary now offers his Mailchimp class online. Learn from a Mailchimp Partner

Learn Mailchimp

Australian Mailchimp Partners

What our clients say

"Gary was awesome! He has a fantastic way of making everything rather simple and straightforward. I definitely left with a lot more knowledge, confidence and ideas than when I walked in. Thanks Gary!" Fiona

View our reviews on Google

Australian Mailchimp Classes

Want to learn Mailchimp?

See Dates

Meet Gary, Mailchimp Expert

Gary Eckstein is listed by Mailchimp as an Expert.

Gary is a Mailchimp Expert and Partner. He delivers Mailchimp training and consulting services in Australia. Gary presents at Mailchimp events and hosts the first, and only, Australian Mailchimp sponsored event.

Contact Gary for your Mailchimp needs

READY TO GET STARTED?

Contact Gary today to get started with Mailchimp consulting, training or integrations.

Get in touch!

Copyright © 2019 · Sitemap · ABN: 40800872179 · Privacy Policy · Terms of Service

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.