Instead of having the client resolve URLS, I want to let my webserver do that. So ideally, I could turn this:

<a href="http://www.long-domain-name.com/">

into this:

<a href="http://domain/">

By putting an entry in my /etc/hosts file, or DNS magic, or something similar. I'm running nginx. Any way I can accomplish that?



You seem to be confusing "qualification" with "resolution".

Resolution is converting the name to an IP address. The client absolutely needs to do this. The only way to avoid this would be to create URLs with the IP address, like so: but that's generally a bad idea and, in many cases, will not work.

Qualification is expanding http://example/ to http://www.example.com/. This also technically needs to be done by the client. However, if all you're trying to avoid is typing the long name, you could use server side includes to expand something shorter into the full URL. Ugly hack, but doable.

Probably the most logical workaround, if you absolutely can't stand the thought of typing the long URLs, would be to write a Makefile that runs your source HTML through sed to convert the short versions to long versions.


Like others said, you cannot alter DNS resolution. It comes way before your webserver got involved at all. If you just want to have shorter URL for the same domain, you can use Apache and mod_rewrite.

e.g., i redirect automatically all mY "example.com" to "www.example.com". You can easily accept all requests for "mydomain.com" and expand that into "www.my-domain-which-has-a-very-long-name.com".

Obviously, you have to register and set DNS records both for "mydomain.com" and "my-domain-which-has-a-very-long-name.com".


The client still has to be able to resolve the DNS no matter what.

The only way around it is if your code or something else physically grabs the page itself and then sends it to the client as its own.


This sounds like something that is normally done by a reverse proxy.

Consider this setup:

The canonical solution is Apache's mod_proxy, but I believe nginx can do this also.


if that www.long-domain-name.com URL is in a page being served from www.long-domain-name.com, then you don't even need to specify the domain. all browsers will fetch an unqualified link from the same site that it came from.

i.e. use a site-relative URL rather than absolute and replace:

<a href="http://www.long-domain-name.com/">


<a href="/">

doing this is a good idea anyway, as it makes it easy to move the site to a different domain name. highly recommended, almost essential, if you want to have a three-stage deployment like "dev.long-domain-name.com" -> "testing.long-domain-name.com" -> "www.long-domain-name.com"

a good rule of thumb in any web development is to avoid absolute URLs whenever possible.

  • If you really need to, then there's <base href="http://www.long-domain-name.com/path/" />. – koenigdmj Jul 21 '09 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.