Alias and rewriterules working together

327 views Asked by At

I have multiple domain names pointing at one Apache2 virtual host:

ServerName domain1.com
ServerAlias domain2.com
ServerAlias domain3.com

To always display the same url I use a rewriterule like this:

RewriteCond %{HTTP_HOST} !^domain1.com [NC]
RewriteRule (.*) http://domain1.com/$1 [R=301,QSA,L]

Finally I have a alias like this:

Alias /niceurl /long/path/to/index.php

Everything works as fine, except that when a user visits domain2.com/niceurl/foo, the url displayed in the browser will be domain1.com/path/to/index.php/foo, rather than domain1.com/niceurl/foo

I should add that the other cases work like expected, in other words:

domain2.com/foo => domain1.com/foo
domain1.com/shorturl/bar => domain1.com/shorturl/bar

Is there a clever way to achieve what I want? Thanks for any hints!

2

There are 2 answers

0
zakjan On BEST ANSWER

Solution is creating a symlink, if you have access to your document root:

ln -s /<path to application> /<document root>/foo
1
rightstuff On

Do you really need a Query String Append (QSA) on a domain redirect?

Try your rule without it:

RewriteRule (.*) http://domain1.com/$1 [R=301]