Способы редиректа

марта 18, 2008 / Автор sowich / Рубрики Программинг / Ответ

Попробую описать основные способы редиректа. Могут быть полезны начинающим дорвейщикам или просто тем, кому необходимо перекинуть свой трафик на ту или иную пагу.

1) с помощью html

<META HTTP-EQUIV=’Refresh’ CONTENT=’1;URL=page.htm’>

2) с помощью JavaScript

location=”http://www.host.com”;
document.location.href=”http://www.host.com” mce_href=”http://www.host.com”;
window.location.reload(“http://www.host.com”);
document.location.replace(“http://www.host.com”);

3) с помощью файла .htaccess

Redirect 301 /page.html http://www.host.com

4) с помощью файла .htaccess с учетом стран

RewriteEngine On
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de-ch.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} at.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} en-gb.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de-at.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de-li.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} fr-ch.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} ch.* [NC,OR]
RewriteCond %{HTTP_ACCEPT_LANGUAGE} de-de.* [NC,OR]
RewriteRule .* http://google.com [R,L]

5) редирект с помощью php

header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: host.com”);

6) редирект с помощью ASP

Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”, “http://www.host.com”
response.end

7) редирект с помощью ASP.NET

<script runat=”server”>;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = “301 Moved Permanently”;
Response.AddHeader(“Location”,”http://www.host.com”);
}
</script>

8) Редирект на ColdFusion

<.cfheader statuscode=”301″ statustext=”Moved permanently”>;
<.cfheader name=”Location” value=”http://www.host.com”>

Вот наиболее часто употребимые способы редиректа. ”Перебрасывайте” На здоровье :)

Комментарии (94) к “Способы редиректа”

Пингбэк и Трэкбек