Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several websites on my development machine under Apache's htdocs folder. Apache Directory root is htdocs, but I want to be able to access each different site there by individual domain names. For example, I have


I have added these lines to my hosts file       dev.site.localhost       cre.site.localhost

Now I want to add an .htaccess file in the htdocs to redirect dev.site.localhost request to htdocs/dev_site_com or

I want to do this so that all of my relative URLs in my site work locally. If I link to a stylesheet in the dev_site_com site using the path /css/style.css, it will work in production, but not in development, because the root is htdocs and not htdocs/dev_site_com

I've never been good with mod_rewrite.. but this is what I have so far..

<IfModule mod_rewrite.c>

    Options +FollowSymLinks
    RewriteEngine on

    RewriteCond %{REQUEST_URI} ^dev\.site\.localhost
    RewriteRule %1 [L]


and nothing is happening

share|improve this question
up vote 1 down vote accepted

You would not usually use rewrite rules to set up different host names on a local server. Instead you would edit your Apache configuration and set up new virtual hosts.

<VirtualHost *:80>
    DocumentRoot /var/www/htdocs/dev_site_com
    ServerName dev.site.localhost

<VirtualHost *:80>
    DocumentRoot /var/www/htdocs/cre_site_com
    ServerName cre.site.localhost

You don't say what type of operating system you are running. If I were doing this on my Ubuntu Linux server I would created two files:

  • /etc/apache2/sites-available/dev
  • /etc/apache2/sites-available/cre

That contain the the virtual host directive for each site respectively, then I would enable each site with the command a2ensite and restart Apache: sudo a2ensite dev && sudo a2ensite cre && sudo service apache2 restart. Here is a full guide to virtual host setup on Ubuntu.

share|improve this answer
Oh right! I've done this before. Thanks! – Nick Rolando Oct 8 '13 at 16:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.