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

I have two domains, which content is in the same file directory:

http://www.alpha.com/

DIR: /var/www/alpha.com/

and

http://www.beta.com/

DIR: /var/www/beta.com/

I want to do the following thing:

When user goes to

http://www.alpha.com/beta/

he should see the content of

http://www.beta.com

and by going e.g. to

http://www.alpha.com/beta/index.php?a=3&b=2

he should see the content of

http://www.beta.com/index.php?a=3&b=2

and so on.

How can I manage that with htaccess?

And in which directory should I place that?

I thought about that:

RewriteEngine On

RewriteRule ^\.htaccess$ - [F]


RewriteCond %{REQUEST_URI} ^/beta/(var1)$

RewriteRule ^.*$ http://beta.com/%1

But it doesnt work. And I'm not good in regular expressions.

Thank you for every answer!

share|improve this question

2 Answers 2

Put the below .htaccess file into /var/www/alpha.com/:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/beta/?$
RewriteRule ^.*$ http://beta.com [L]
RewriteCond %{REQUEST_URI} ^/beta/(.*)$
RewriteRule ^.*$ http://beta.com/%1 [L]
  • question mask ?: makes the preceding token optional
  • L flag: means the last rule
share|improve this answer
    
Yep, that wroks for me! Thanks! Question solved. –  Max Sep 16 '11 at 7:58

Do you need to use the .htaccess file? If not, using VirtualHosts in the httpd.conf file might be better than a rewrite.

 <VirtualHost *:80>
DocumentRoot /www/alpha.com/
ServerName www.alpha.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/beta.com
ServerName www.beta.com
</VirtualHost> 
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.