views:

9

answers:

1

Background:

Suppose I have a website that is hosted on http://www.example.com and the site has a lot of absolute internal links. Something happens that requires me to move the entire website to http://www.example.net with all other things remaining the same.

Obviously, I can do a global search and replace on the website code to fix this, but what I am wondering is how many ways can I create a permanent linking scheme that will never break regardless of what site I move to, as long as the relative paths are the same.

NOTE: replace example.com and example.net with the names of two totally different web-hosting companies. They were just used for generic names that do not provide free advertising.

Question:

How many different ways are there to support permanent hyperlinks such as:

http://some-aribitrary-string.com/some/path/here/page.htm

Such that:

  • some-arbitrary-string represents a unique string that will never have to change
  • some-arbitrary-string resolves to the DNS entry or IP address of whatever machine my code happens to be hosted on at any given time
  • if and when I have to change servers, I only have to update this information in one place (instead of having to do global string search and replace)
  • in order to use this scheme I do not have to have access to DNS records
+1  A: 

A Rewrite should be enough:

RewriteEngine On
RewriteRule ^(.*)$ http://some-arbitrary-string.com/$0 [L]

You could additionally use [P] or [R=301] to route requests through an internal proxy or properly redirect them.

You