I recently went live with a new website and one of the departments on campus referred users to a virtual domain.

For example, www.ia.domain.com masked itself as its own website, which was really domain.com/ia

What I want to do, is redirect everyone who hits www.ia.domain.com, to go to domain.com/ia,

as well as www.ia.domain.com/faculty/ => domain.com/ia/faculty/

This is on a new box, so it does not have the original configuration.

The site is being run on Apache, using linux (rhel5).

I am unfamiliar with mod_rewrite. I have done 301 redirects, but I am unable to redirect a virtual sub-domain that way.

4 Answers 4


How about not using mod_rewrite and instead using the redirect statement.

#Virtual Host for IA sub web
<VirtualHost *:80>
   ServerName www.ia.domain.com
   ServerAlias <other domain names they want to associate with this directory; ex: ia.domain.com>
   Redirect permanent / http://www.domain.com/ia_new_web_location/

You'll need a name-based virtualhost set up for www.ia.domain.com

Inside the virtualhost configuration block, the following rule for mod_rewrite should do the trick:

RewriteRule ^/(.*) http://domain.com/ia/$1 [R]

Here's what I expect would work, in your Apache configuration (/etc/httpd/conf.d or /etc/apache2/conf.d, a file named, for example, domain.com.conf):

This may need to be adjusted depending on what other Apache configurations you have, of course.

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName www.ia.example.com
   ServerAlias ia.exmaple.com
   Redirect permanent /(.*) http://www.example.com/ia/$1

<VirtualHost *:80>
   #  Your normal website configurations here



if you want have a transparent redirection, try this :

rewriteCond %{HTTP_HOST} ^www.ia.domain.com
rewriteRule ^/faculty(.*) domain.com/ia/faculty$1 [P]

The apache server use proxy module (you need enable proxy module) to make a transparent redirection (no 301 or 302 http code)

  • Note that this is a proxy, so the address bar won't change, it will stay at the original URL. This doesn't seem to be what the original poster was asking. Also, the destination in the proxy should begin with "http://". Just to be clear on the terminology, it's probably better to call this a proxy not a "transparent redirection". Sep 4, 2009 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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