Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

<a href="">

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?


share|improve this question
up vote 3 down vote accepted

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 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.

share|improve this answer

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 "" to "". You can easily accept all requests for "" and expand that into "".

Obviously, you have to register and set DNS records both for "" and "".

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

if that URL is in a page being served from, 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="">


<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 "" -> "" -> ""

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

share|improve this answer
If you really need to, then there's <base href="" />. – koenigdmj Jul 21 '09 at 23:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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