1

Just a quick beginner's question here. I have a webapp located at domainxyz.com, and it generates short URLs for long posts automatically - so rather than visit domainxyz.com/reallylongpostnamehere I can just type domainxyz.com/a5c and be taken there automatically.

However, I've bought a shorter domain name - short.com - and I want to be able to visit short.com/a5c and be redirected (or forwarded) to domainxyz.com/a5c. Or short.com/7f0 --> domainxyz.com/7f0. This way, although it seems a tad illogical it saves me setting up another hosting account on short.com to deal with the URL shortening.

Is this possible? I realise you can forward domains, but, can you forward domains AND forward the URL segments?

Thanks!

Jack

Jack
  • 169
  • 2
  • 2
  • 10

2 Answers2

3

You can set up an A record for short.com to point the same address as is given in the A record for domainxyz.com so your users trying to visit http://short.com/a5c will actually send their requests to the same server as domainxyz.com though it will appear as short.com in their address bar and the HTTP server at domainxyz.dom will see in the requests a host header containing the original URI with short.com in it.

Another way to solve your problem is to set up an HTTP rewrite service on the server at short.com that will rewrite URLs to have the hostname domainxyz.com. In nginx it will be something like:

server {
  server_name short.com www.short.com;

  location / {
    rewrite (.*) http://www.domainxyz.com$1 permanent;
  }
}

I do not know anything about configuring this with apache's mod_rewrite or lighttpd but I believe this is also possible with them.

Greg A. Woods
  • 244
  • 4
  • 10
timurb
  • 347
  • 4
  • 12
  • I just came across this question today and I see this answer also makes a misleading suggestion which is actually incorrect, and as the accepted answer that may mislead other readers somewhat. – Greg A. Woods Sep 01 '15 at 18:25
  • Thanks for updating! CNAMEs can only be used for 3rd level domains and longer ones. – timurb Sep 03 '15 at 05:17
  • The level is irrelevant -- CNAMES can only be used for domains where absolutely no other resource records are used. – Greg A. Woods Sep 03 '15 at 19:05
  • You can either use A or CNAME -- I think this was in my initial posting. What I was missing is you can't use CNAMEs for 2nd level domains.Thank you for correcting me in this! – timurb Sep 04 '15 at 20:41
  • 1
    The level is irrelevant -- anywhere _any_ other records are required, such as where an SOA and NS records are required, there cannot be a CNAME. An SOA and NS records are not always at the second level -- take for example *example.co.uk* where the SOA would be at the third level. – Greg A. Woods Sep 04 '15 at 20:45
  • Right. I haven't ever though of such case because it is quite unlikely these days for most of the world. Anyway I appreciate your edit, thanks! – timurb Sep 06 '15 at 04:15
  • Well the rule about CNAME being the lone RR is important for every CNAME, no matter what level it is at or what purpose it might be intended for, so if you remember the rule correctly then it also works for this particular purpose and you don't have to care what "top" level domain(s) you are working with. The downside here is that an SOA and NS records are required even if one wants _example-a.co.uk_ to behave exactly the same as _example-b.co.uk_ so while a CNAME might seem like an ideal solution, it cannot be used. – Greg A. Woods Sep 06 '15 at 05:51
0

In addition to what Erthad has said, you can also accomplish this using pound - a reverse proxy and load-balancer - using the "Redirect" configuration.

sybreon
  • 7,405
  • 1
  • 21
  • 20
  • Pound looks pretty intense. Just a shame I can't use it on MediaTemple ;) but thank you for your suggestion! – Jack Jun 16 '10 at 09:09