-1

I have got apache2 server with one virtual host. It is typo3 CMS. There are multiple pages:

foo.com -- DNS A record --> 32.32.32.32
  |_ foo.com/bar/
  |_ foo.com/baz/

Now I want to configure other domain (qux.com, also with A record to IP same as below) to redirect it to foo.com/baz/, for example when user put qux.com in browser I want him to see qux.com in address bar and foo.com/baz/ webpage. In order to do this I have put this configuration to file in sites-enabled:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^qux.com
RewriteRule ^(.*) http://foo.com/baz/ [P]

but it has no effect. What is a cause? How to configure it properly?

Edit: here is my vhost config:

<VirtualHost *:80>
        ServerName foo.com
        ServerAlias *.foo.com
        ServerAlias qux.com
        RewriteEngine On
        RewriteCond %{HTTP_HOST} ^qux.com
        RewriteRule ^(.*) http://foo.com/baz/ [P]
        DocumentRoot /var/builds/stage
        <Directory /var/builds/stage>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>
Karaal
  • 11
  • 6

1 Answers1

1

Wouldn't it be easier to add another VirtualHost?

<VirtualHost *:80>
        ServerName qux.com
        ServerAlias *.qux.com
        Redirect / http://foo.com/baz/
</VirtualHost>
Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122
  • It is works, but i don't want users see the target URL. – Karaal Mar 03 '15 at 10:47
  • With RewriteRule you'll end up redirecting the user to another domain anyway. Still, another VirtualHost is the correct solution. Just replace Redirect directive with `DocumentRoot /var/builds/stage/baz/` You really should read [link](http://httpd.apache.org/docs/2.4/vhosts/examples.html) examples first – it's all thoroughly explained there with all the suitable examples. – Esa Jokinen Mar 03 '15 at 11:08