Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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,

http://hostname/site1 
http://hostname/site2

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 stackoverflow.com Feb 20 '10 at 15:49

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

2 Answers 2

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 http://192.168.1.100 will rewrite to http://192.168.1.100/site2/ However, I also setup a DNS make myHost.com resolve to 192.168.1.100. now the rewrite doesn't work for http://myHost.com Can anyone help, please? Thanks a lot!

EDIT: just found solution by adding another rewrite rule.

share|improve this answer

Your Answer

 
discard

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.