Blog Home

The journal of graphic designer Scotty Vernon.

Version 0.83 11:34 GMT ×° - Downloading weather report...

Redirect a subdomain to a directory on a main domain using .htaccess

By Scotty at 3:19 am | Articles / Code Snippets | one comment

For anyone looking to setup a rediret from a subdomain to a main domain, the best way to do it is using the .htaccess file. Goto the root directory for your subdomain, enter the following code into the .htaccess file…

(Obviously changing blog and yoursite to whatever you need.)

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog.yoursite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.blog.yoursite.com$
RewriteRule ^(.*)$ http://www.yoursite.com/blog/$1 [R=301,L]

This will perform a 301 redirect on the subdomain and redirect it whatever directory on the main domain.

One Response

Thank you so much for posting this. The redirection setup at my host’s Cpanel didn’t seem to be working properly, so I had to update my .htaccess file manually. This did the trick!

Leave a Response

  • Required
  • Required