301 Permament Redirect rules. How to make 301 Permament Redirect?
Three hundred and first error (301 Permament Redirect), returned when referring to a specific page address, means that the site has been permanently moved to new address, as specified in the HTTP header. As the user logging in through a browser, and search bots will be redirected to the new address, at the same time, the search engines for all of the properties of the old address (page) will be transferred to the new URL. In the 301 will stitch the old and new addresses: parameters such as PageRank and TCI, as well as page weight and reference weight of the old addresses will be transferred to a new URL.
Redirect error number 301 (moved permanently) is the best way to keep your ranking in search engines when you transfer it to a new domain or change the content management system. Forwarding can be done in several ways, depending on the software installed.
301 to. Htaccess
If you are using Apache (apache) server, call forwarding, you can simply run through the file. Htaccess, but at the same time, do not forget to include modules mod_alias (to support the directives of Redirect, RedirectPermanent and RedirectMatch) and / or mod_rewrite (for revrayta) in php . ini.
Redirect Redirect directive or RedirectPermanent module mod_alias
Redirect 301 / old-page.html http://new-domain.ru/new-page.html
or
Redirect permanent / old-page.html http://new-domain.ru/new-page.html
The disadvantage of this method is that all the addresses that you want to redirect, you need to enumerate one by one, each separately. You can also use RedirectPermanent for similar purposes.
RedirectPermanent / old-url.html http://new-site.ru/new-url.html
Redirect RedirectMatch directive
This redirection is similar to the previous one, except that you can specify a regular expression to the old URL. Let us assume, by changing the engine from PHP to ASP, you can redirect the old addresses as follows:
RedirectMatch /(.*) \. Php $ / $ 1.aspx
Redirect using mod_rewrite module RewriteRule directive
To use the RewriteRule directive is necessary to make sure that the httpd.conf is connected module mod_rewrite, and switches on the option FollowSymLinks. Using revrayt module provides many opportunities to redirect the pages to the new address.
Redirect domain to www non-www
Options + FollowSymLinks
RewriteEngine On
RewriteCond% {HTTP_HOST} ^ www \ .(.*) [NC]
RewriteRule ^(.*)$ http://% 1 / $ 1 [R = 301, L]
or an alternative, more intuitive syntax
Options + FollowSymLinks
RewriteEngine On
RewriteCond% {HTTP_HOST} ^ www.domain \. Com $ [NC]
RewriteRule ^(.*)$ http://domain.com/ $ 1 [R = 301, L]
Redirect requests from non-www to www domain prefix
Options + FollowSymLinks
RewriteEngine On
RewriteCond% {HTTP_HOST} ^ domain \. Com $ [NC]
RewriteRule ^(.*)$ http://www.domain.com/ $ 1 [R = 301, L]
or alternatively
RewriteEngine On
RewriteCond% {HTTP_HOST}! ^ Www \ .(.*) [NC]
RewriteRule ^(.*)$ http://www.% 1 / $ 1 [R = 301, L]
Redirect using a script (sending headers)
Redirect queries can also perform with scripts by sending the client the necessary headers.
HTTP/1.1 301 Moved Permanently
Location: http://www.newdomain.ru/newdir/newpage.htm
PHP redirect
header ("HTTP/1.1 301 Moved Permanently");
header ("Location: http://www.newdomain.ru/newdir/newpage.htm");
exit ();
?>
ASP redirect
<% @Language = VBScript%>
<%
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.new-url.com"
response.end
%>
ASP.NET redirect
ColdFusion redirects
<.cfheader statuscode = "301" statustext = "Moved permanently">
<.cfheader name = "Location" value = "http://www.new-url.com">
JSP (Java) redirect
<%
response.setStatus (301);
response.setHeader ("Location", "http://www.new-url.com/");
response.setHeader ("Connection", "close");
%>
CGI PERL
$q = new CGI;
print $ q-> redirect ("http://www.new-url.com/");
Ruby on Rails
def old_action
headers ["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end
Implementation of the redirect to nginx
if ($ host = 'www.domain.com') {
rewrite ^(.*)$ http://domain.com $ 1 permanent;
}
|