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 this article is very simple
Add 301 redirect instructions to the. htaccess file
The use of "mod_rewrite" technology, in the form of:
The code is as follows |
Copy Code |
Rewriteengine on Rewriterule ^ (. *) $ http://xxx.com/$1 [r=301,l] |
1. redirect domain.com to www.domain.com
This redirect is designed to make the domain name unique, is the website SEO must do, the back redirects www.domain.com to domain.com is also for the same reason, but the form is different. Open the. htaccess file and add the following rules. (The following rule is for the primary domain name, and the subdomain is to be modified)
The code is as follows |
Copy Code |
Rewriteengine on Rewritecond%{http_host}!^www.domain.com$ [NC] Rewriterule ^ (. *) $ http://www.domain.com/$1 [l,r=301] |
2. redirect www.domain.com to domain.com
The code is as follows |
Copy Code |
Rewriteengine on Rewritecond%{http_host}!^domain.com$ [NC] Rewriterule ^ (. *) $ http://domain.com/$1 [l,r=301] |
3. REDIRECT olddomain.com to www.newdomain.com
The code is as follows |
Copy Code |
Rewriteengine on Rewritecond%{http_host}!olddomain.com$ [NC] Rewriterule ^ (. *) $ http://www.newdomain.com/$1 [l,r=301] |
4. redirect olddomain.com to newdomain.com
The code is as follows |
Copy Code |
Rewriteengine on Rewritebase/ Rewritecond%{http_host}!olddomain.com$ [NC] Rewriterule ^ (. *) $ http://newdomain.com/$1 [l,r=301] |
5. redirect domain.com/file/file.php to otherdomain.com/otherfile/other.php
The code is as follows |
Copy Code |
Rewritecond%{http_host} ^www.domain.com$ Rewriterule ^file/file.php$ http://www.otherdomain.com/otherfile/other.php [r=301,l] |
Implement 301 redirects with asp/php:
Asp:
The code is as follows |
Copy Code |
Response.status= "Moved Permanently" Response.AddHeader "Location", "http:///" Response.End |
Php:
code is as follows |
copy code |
Header (" http/1.1 moved Permanently "); Header (" location:http:///"); Exit (); |