Simple Redirect Subdomain to a Directory

If you are running Apache for your web server, and mod_rewrite is installed (this is a pretty typicaly module on all installations) this is actually pretty easy.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain\.yourdomain\.com
RewriteRule ^(.*)$ http://www\.yourdomain\.com/subdomain/$1 [L]

Add this code to your apache configuration file – the easiest location is in the .htaccess file in your root web directory. This should redirect the browser with a 302 Found message.

You can do some pretty fancy things with mod_rewrite, but this is simple and gets the job done!

Share and Enjoy:
  • Twitter
  • del.icio.us
  • Digg
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Print
  • StumbleUpon

1 Trackbacks

You can leave a trackback using this URL: http://systembash.com/content/simple-redirect-subdomain-to-a-directory/trackback/

  1. By Dave Drager on November 2, 2008 at 1:57 am

    New blog post: Simple Redirect Subdomain to a Directory http://tinyurl.com/6qwzml

Post a Comment

Your email is never shared. Required fields are marked *

*
*