开发者

permanent-id-based hyperlinking scheme for Web HTTP/HTTPS, how many ways can it be done?

开发者 https://www.devze.com 2023-01-07 12:56 出处:网络
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:

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/s开发者_运维知识库ome/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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消