Friends who use ASP.net and follow the new technology may already know that the Response.redirectpermanent () method has been added in ASP.net 4.0 to achieve permanent redirection, and the effect of the method is clearly explained in the annotation: execution from the requested URL to the specified A permanent redirection of URLs and provides options for completing the response.
In the ASP.net MVC 3 project, we can use the following notation to implement permanent redirection as needed:
The code is as follows |
Copy Code |
Public ActionResult Index () { Return redirectpermanent ("contact"); Return redirecttoactionpermanent ("contact"); Return redirecttoroutepermanent ("contact"); } |
We used to be able to set the status code in the HTTP data stream returned by the server, such as specifying a status code of 301 for permanent redirection, and now in asp.net 4.0, asp.net Web forms projects and ASP.net MVC projects, we can easily implement URLs permanently redirect.
The implementation of the domain name from the WWW to the permanent redirect to the domain name without www, the webmaster to do so is to improve the ranking of domain names.
Some friends may use the method of comparing benzene, add Response.redirectpermanent method under each Controller. The simpler approach is to add the following code to the Global.axax.cs:
The code is as follows |
Copy Code |
protected void Application_BeginRequest (object sender, EventArgs e) { String strurl = Request.Url.ToString (). Trim (). ToLower (); if (Strurl.contains ("Http://111cn.net")) { Response.redirectpermanent ("Http://www.111cn.net"); Not good } }
|
If you are serious, you will find that the wording is somewhat unfriendly, and the following wording is better:
The code is as follows |
Copy Code |
Response.redirectpermanent (Strurl.replace ("Http://111cn.net", "http://www.111cn.net")); Good |
The following days tell you how to force a user or seo/seo.html "target=" _blank > Search engine Redirect to a unique domain name in. htaccess.
. The code is as follows:
The code is as follows |
Copy Code |
#强制重定向到www Rewriteengine on Rewritecond%{http_host} ^111cn.net/[NC] Rewriterule ^ (. *) $ http://www.111cn.net/$1 [l,r=301] #强制重定向到不带www的顶级域名 Rewriteengine on Rewritecond%{http_host}!^111cn.net/$ [NC] Rewriterule ^ (. *) $ http://111cn.net/$1 [l,r=301] |
iis301 is very simple. Just create two sites and then use one to jump to another to configure without introducing.
This article is very simple, but many people in the process of permanent redirection is wrong, I hope to help