Question

Am trying to do the following. My website is hosted on

www.sitehost.com/uk

But I own this domain.

www.mainsite.co.uk

Is it possible to redirect the user hitting www.mainsite.co.uk to www.sitehost.com/uk but retain the www.mainsite.co.uk?

I tried doing .htaccess redirect and it worked but it changed the URLs from www.mainsite.co.uk to www.sitehost.com/uk

Ideally it would work like so...

www.sitehost.com/uk/post/20

can be accessed via

www.mainsite.co.uk/post/20

I tried mod_proxy but it didn't seem to work all the way. Anyone know how to do this? Is this even possible with Apache?

Was it helpful?

Solution

This is possible if mod_proxy is enabled in your Apache config.

Once mod_proxy and mod_rewrite are enabled place this rule in your DocumentRoot/.htaccess file of sitehost host:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?sitehost\.com$ [NC]
RewriteRule ^ http://www.mainsite.co.uk%{REQUEST_URI} [L,P]

P flag is used for proxying the request to external URL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top