apache - Redirect/rewrite alternative domains to root domain with apache2/htaccess -


i 2 domains , without www prefix. when user visits of these domains, want automatically reroute chosen 1 of them.

for example:

domain.com www.domain.com domain.co.uk www.domain.co.uk 

when user visits www.domain.com, domain.co.uk or www.domain.co.uk, rewrite domain.com

so far, have apache2 virtual host block setup this:

<virtualhost *:80>   proxypass / http://localhost:3060/   proxypassreverse / http://localhost:3060/   servername domain.com   serveralias www.domain.com   serveralias domain.co.uk   serveralias www.domain.co.uk </virtualhost> 

but doesn't rewriting/rerouting. need make sure takes account paths. example, www.domain.co.uk/test change domain.com/test

any ideas how can in virtual host block? i'm assuming split 3 domains rewritten separate block , treat them there, not sure how accomplish rules need.

per comment, want redirect 3 aliases main domain, , you've stated within virtual host configuration.

<virtualhost *:80>     ...      rewriteengine on      # if using 1 of aliases ...     rewritecond %{http_host} ^www\.domain\.com$ [or]     rewritecond %{http_host} ^(www\.)?domain\.co\.uk      # ... redirect main domain     rewriterule ^(.*)$ http://domain.com/$1 [r=302,l] </virtualhost> 

you can add rewrite* directives in domain's .htaccess file.

to make redirect permanent, change 302 301 - instructs browsers , search engines cache redirect.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -