Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

OS: CentOS 5.3 Apache 2.2.3

Say I have two site hosted on the machine (/var/www/html/site1 and /var/www/html/site2). For now,


brings to the site. and http://hostname brings to apache welcome page. Is there any way to make (http://hostname) direct to site1 by just changing configuration but not moving folder structures? Thanks a lot!!

share|improve this question

migrated from Feb 20 '10 at 15:49

This question came from our site for professional and enthusiast programmers.

You want one of the Redirect* directives.

share|improve this answer
Im having problem with below setting. I want make hostname redirect to hostname/site2. But seems it will cause infinity loop. <code> Redirect permanent / hostname/site2 </code> – Stan Feb 19 '10 at 2:26
up vote 1 down vote accepted

I found an answer below.

# Turn on rewrites. 
RewriteEngine on
# Only apply to URLs on this domain 
RewriteCond %{HTTP_HOST} ^192\.168\.1\.100$ (this seems unnecessary)

# Only apply to URLs that aren't already under folder. 
RewriteCond %{REQUEST_URI} !^/site2/
RewriteCond %{REQUEST_URI} !^/site2

# Don't apply to URLs that go to existing files or folders. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /folder. 
RewriteRule ^(.*)$ /site2/$1

# Also redirect the root folder. 
RewriteCond %{HTTP_HOST} ^192\.168\.1\.100$ 
RewriteRule ^(/)?$ /site2/index.php [L]
RewriteCond %{HTTP_HOST} ^myHost\.com$ 
RewriteRule ^(/)?$ /site2/index.php [L]

So now will rewrite to However, I also setup a DNS make resolve to now the rewrite doesn't work for Can anyone help, please? Thanks a lot!

EDIT: just found solution by adding another rewrite rule.

share|improve this answer

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.