Question

I own two domains, RiverSparrow and rs.co. What I want to do is use the short domain as a parallel to the main domain, without having to upload the same file structure on each server. So what I would like to do is be able to catch any request that comes in to rs.co, preferably using just one file (or a combination - but the point is that I don't want to have to upload the same file to every folder on the server), then reconstruct the URL as before but substituting rs.co for riversparrow.co.uk. The URL formatting I can do - it's the catching any request no matter the URL that I have problems with. I'm open to any suggestions. I have some notion that it may need htaccess, which is fine, but feel free to do it in any language (though server-side not PHP will need installation).

Was it helpful?

Solution

The best way to go is obviously to assign both domains to the same virtual webhost - nothing more to do.

If you do need to go down the described route, take a look at custom 404 handlers - basically you

  • leave the complete server empty apart from a single script, that does not exist on the other server (e.g. my404hander.php)
  • You dedicate this script as custom 404 handler in Apache

This leads to this control flow:

  • A client requests /some/url
  • This is not found (server is basically empty), leading to 404 error
  • Your custom handler is invoked
  • it is now able to construct the coreseponding URL and do whatever it seems it should, e.g. send a redirect

OTHER TIPS

Contrary to Eugen’s answer, I would rather suggest using Redirect directive … “abusing” the 404 handler feels dirty.

Plus you would not have to do any “URL reconstruction” – because apache will do it for you.

Redirect permanent / http://riversparrow.co.uk should do it.

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