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.

This is my apache configuration (most interesting part of it):

<VirtualHost *:80>
  ServerName example.com
  ...
</VirtualHost>

Works fine and my server properly responds to example.com:80 HTTP requests. Now I'm going to add an alias to this domain. I want all requests to my-new-domain.com:80/test produce the same responses as to example.com, for example:

my-new-domain.com/test/xyz -> example.com/xyz

What is important, I don't want to see HTTP redirections (301 code). I want to hide example.com URL from a user. All that he has to see is my-new-domain.com/test URL.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

put

ServerAlias my-new-domain.com

inside the VirtualHost section

for the rewrite

RewriteCond %{HTTP_HOST}   ^my-new-domain\.com
RewriteRule /test/(.*)     /$1                   [QSA,L,P]
share|improve this answer
    
No, that doesn't deal with the /test part. –  nickgrim Mar 10 '11 at 8:39
    
Exactly, this is just the first part of the solution. Then I need to use RewriteRules, but can't understand how to specify them properly.. @jamespo can you help? –  yegor256 Mar 10 '11 at 8:59
    
many thanks! Btw, do you know how to specify rules when I need to extend URL paths: my-new-domain.com/xyz -> example.com/test/xyz? –  yegor256 Mar 10 '11 at 21:07
add comment

Use mod_rewrite with mod_proxy (https://httpd.apache.org/docs/2.2/mod/mod_rewrite.html). Otherwise, if domains differ, mod_rewrite performs an external rewrite even if both are served from the same host.

Something like

RewriteRule ^http://my-new-domain.com/test http://example.com [QSA,P]

Another solution would be to create a symlink test in my-new-domain.com’s root dir to the root dir of example.com.

share|improve this answer
    
RewriteRules don't match on the full URL I don't think? –  jamespo Mar 10 '11 at 11:14
add comment

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.