Privacy Policy Cookie Policy Terms and Conditions URL redirection - Wikipedia, the free encyclopedia

URL redirection

From Wikipedia, the free encyclopedia

URL redirection, also called URL forwarding, domain redirection and domain forwarding, is a technique on the World Wide Web for making a web page available under many URLs.

Contents

[edit] Purposes

There are several reasons for a webmaster to use redirection:

[edit] Similar domain names

Users might search for the same information under slightly different URLs, e.g. gooogle.com and googel.com. An organization can register these domains and re-direct them to the correct location: google.com..

[edit] Moving a site to a new domain

A Web site might change its domain name for several reasons. An author might move his pages to a different section of the same site. With URL redirects, you can direct incoming links from other sites to the new location.

The same applies to search engines: They have crawled your old domain and send visitors to the URLs that they found then. By using a "moved permanently" redirect to the new URL, visitors will still find your pages. Also, in the next crawl, the search engine will use the new URLs instead of the old ones.

[edit] Logging outgoing links

The access logs of a web server keep detailed information from where your visitors came, how they browsed your site — but not to which sites they left by following a link on your pages. This is because the browser has no need to communicate with your server when the visitor clicks on an out-going link.

With a gateway page, you can capture this information: Instead of sending the visitor straight to the other site, you direct him to a URL on your domain that affects an automatic redirect to the real target. Except for the delay of the additional request to your server, the visitors don't see a difference. However, they leave a trace in your server logs.

Note: There are other techniques besides redirects that achieve the same goal of logging outgoing links.

[edit] Short, meaningful, persistent aliases for long or changing URLs

Currently, web engineers tend to pass descriptive attributes in the URL to represent data hierarchies, command structures, transaction paths and session information. This results in an URL that is aesthetically unpleasant and difficult to remember. Sometimes the URL of a page changes even though the content stays the same.

[edit] Manipulating search engines

Some years ago, redirect techniques were used to fool search engines. For example, one page could show popular search terms to search engines but redirect the visitors to a different target page. There are also cases where redirects have been used to "steal" the page rank of one popular page and use it for a different page.

Of course, search engine providers noticed the problem and took appropriate actions: Usually, sites that employ such techniques to manipulate search engines are punished automatically by reducing their ranking or by excluding them from the search index.

As a result, today, such manipulations usually result in less rather than more site exposure.

[edit] Satire and criticism

In the same way that a Google bomb can be used for satire and political criticism, a domain name that conveys one meaning can be redirected to any other web page, sometimes with malicious intent.

[edit] Manipulating visitors

URL redirection is sometimes used as a part of phishing attacks that confuse visitors about which web site they are visiting.

[edit] Techniques

There are several techniques to implement a redirect. In many cases, Refresh meta tag is the simplest one. Note, however, that there are weighty opinions that discourage this methods (see below).

[edit] Manual redirect

The simplest technique is to ask the visitor to follow a link to the new page:

Please follow <a href="http://www.example1.com/">link</a>!

This method is often used as a fallback for one of the following methods: If the visitor's browser does not support the automatic redirect method, the visitor can still reach the target document by clicking on the link.

[edit] HTTP status codes 3xx

In the HTTP computer protocol used by the World Wide Web, a redirect is a response with a status code beginning with 3 that induces a browser to go to another location.

The HTTP standard defines several status codes for redirection:

  • 300 multiple choices (eg. offer different languages)
  • 301 moved permanently
  • 302 found (e.g. temporary redirect)
  • 303 see other (e.g. for results of cgi-scripts)
  • 307 temporary redirect

All of these status codes require that the URL of the redirect target is given in the Location: header of the HTTP response. The 300 multiple choices will usually list all choices in the body of the message and show the default choice in the Location: header.

Within the 3xx range, there are also some status codes that are quite different from the above redirects (they are not discussed here with their details):

  • 304 not modified
  • 305 use proxy
  • 306 not used

Here is a sample of a HTTP response that uses the 301 "moved permanently" redirect:

HTTP/1.1 301 moved permanently
Location: http://www.wikipedia.org/
Content-type: text/html
Content-length: 78

Please follow <a href="http://www.wikipedia.org/">link</a>!

Notes:

  • Often, web authors don't have sufficient permissions to produce these status codes: The HTTP header is generated by the web server program and not read from the file for that URL. Even for CGI scripts, the web server usually generates the status code automatically and allows custom headers to be added by the script. To produce HTTP status codes with cgi-scripts, one needs to enable non-parsed-headers.
  • However, it might be sufficient to print the "Location: 'url'" header line from a normal CGI script. Many web servers choose one of the 3xx status codes for such replies.

A previous version of this document contained the following advice:

The HTTP protocol requires that the redirect be sent all by itself, without any web page data. As a result, the web programmer who is using a scripting language to redirect the user's browser to another page must ensure that the redirect is the first or only part of the response. In the popular ASP scripting language, this can also be accomplished using the methods response.buffer=true and response.redirect "http://www.example.com". Using PHP, the popular open source language, one can use header("Location: http://www.example.com");.

[edit] Refresh Meta tag and HTTP refresh header

Netscape introduced a feature to refresh the displayed page after a certain amount of time. It is possible to specify the URL of the new page, thus replacing one page after some time by another page:

A timeout of 0 seconds means an immediate redirect.

Here is an example of a simple html document that uses this technique:

<html><head>
  <meta http-equiv="refresh" content="0; url=http://www.wikipedia.org/">
</head><body>
  Please follow <a href="http://www.example.com/">link</a>!
</body></html>

Notes:

  • This techinque is usable by all web authors because the meta tag is contained inside the document itself.
  • Put the meta tag into the head secion of the html file!
  • Note the strange syntax of the content field.
  • Replace the number 0 in this example by another number to achieve a delay of as many seconds.
  • If you just want to redirect to another page, don't add a delay: This is annoying!
  • This is a proprietary/non-standard extension by Netscape. It is supported by most web browsers.

Here is an example of achieving the same effect by issuing a HTTP refresh header:

HTTP/1.1 200 ok
Refresh: 0; url=http://www.example.com/
Content-type: text/html
Content-length: 78

Please follow <a href="http://www.example.com/">link</a>!

This response is easier to generate by CGI programs because one does not need to change the default status code. Here is a simple CGI program that affects this redirect:

#!/usr/bin/perl
print "Refresh: 0; url=http://www.example.com/\r\n";
print "Content-type: text/html\r\n";
print "\r\n";
print "Please follow <a href="http://www.example.com/">link</a>!"

Note: Usually, the HTTP server adds the status line and the Content-length header automatically.

Note: This method is considered by the W3C to be a poor method of redirection, since it does not communicate any information about either the original or new resource, to the browser (or search engine). The W3C's Web Content Accessibility Guidelines (7.4) discourage the creation of auto-refreshing pages, since most web browsers do not allow the user to disable or control the refresh rate.

[edit] JavaScript redirects

JavaScript offers several ways to display a different page in the current browser window. Quite frequently, they are used for a redirect. However, there are several reasons to prefer the refresh meta tag (whenever it is possible) over JavaScript redirects:

  • There are several reasons for some users to disable JavaScript:
    • Security considerations
    • Some browsers don't support JavaScript
    • many crawlers (e.g. from search engines) don't execute JavaScript.
  • There is no "standard" way of doing it: If you search for "you are being redirected" and inspect the returned pages, you find that virtually each JavaScript redirect employs different methods. This makes it difficult for Web client programmers to honour your redirect request without implementing all of JavaScript.

[edit] Frame redirects

A slightly different effect can be achieved by creating a single html frame that contains the target page:

<frameset rows="100%">
  <frame src="http://www.example.com">
</frameset>
<noframes>
  Please follow <a href="http://www.example.com/">link</a>!
</noframes>

One main difference to the above redirect methods is that for a frame redirect, the browser displays the URL of the frame document and not the URL of the target page in the URL bar.

This technique is sometimes called "cloaking".

[edit] Redirect loops

It is quite possible that one redirect leads to another redirect. For example, the URL http://www.wikipedia.com/wiki/URL_redirection (note the differences in the domain name) is first redirected to http://www.wikipedia.org/wiki/URL_redirection and again redirected to the correct URL: http://en.wikipedia.org/wiki/URL_redirection. This is appropriate: the first redirection corrects the wrong domain name. The second redirection selects the correct language section. Finally, the browser displays the correct page.

Sometimes, however, a mistake can cause the redirection to point back to the first page, leading to an infinite loop of redirects. Browsers usually break that loop after a few steps and display an error message instead.

The HTTP standard states:

  • A client SHOULD detect infinite redirection loops, since such loops generate network traffic for each redirection.
  • Note: previous versions of this specification recommended a maximum of five redirections. Content developers should be aware that there might be clients that implement such a fixed limitation.

[edit] Services

Sometimes, you can use one of the above methods without rolling it all on your own: Use a service that does the technical work for you:

[edit] Wikipedia redirects

Wikipedia contains pages whose sole purpose is to redirect the user's browser to a different page. They exist to allow users to enter alternate spellings or names for articles, and redirect them promptly to the article they were most likely looking for. Help with this feature is found by clicking the redirect link.

[edit] URL redirection services

URL redirection services exist to shorten long URLs.

Some web publishers have criticized the use of these services, arguing that replacing an URL with an encoded shortcut effectively erases information from a document.

[edit] URL obfuscation services

There exist redirection services for hiding the referer using META refresh.

[edit] External links

In other languages
THIS WEB:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia 2008 (no images)

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -

Static Wikipedia 2007:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu

Static Wikipedia 2006:

aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - be - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - closed_zh_tw - co - cr - cs - csb - cu - cv - cy - da - de - diq - dv - dz - ee - el - eml - en - eo - es - et - eu - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gd - gl - glk - gn - got - gu - gv - ha - haw - he - hi - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mg - mh - mi - mk - ml - mn - mo - mr - ms - mt - mus - my - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - rm - rmy - rn - ro - roa_rup - roa_tara - ru - ru_sib - rw - sa - sc - scn - sco - sd - se - searchcom - sg - sh - si - simple - sk - sl - sm - sn - so - sq - sr - ss - st - su - sv - sw - ta - te - test - tet - tg - th - ti - tk - tl - tlh - tn - to - tokipona - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu