We have summarized the implementation code of the current mainstream program 301 page Jump, including asp, asp.net jsp, php cgi perl, etc. Generally, as long as it is a server program, it can jump 301, other status codes can also be implemented.
2. Code redirection in ASP 301
The Code is as follows: |
Copy code |
<% @ Language = VBScript %> <% Response. Status = "301 Moved Permanently" Response. AddHeader "Location", "http: // www. Your Website address. cn/articles/301 /" %> |
3. 301 redirection code under ASP. Net
The Code is as follows: |
Copy code |
<Script runat = "server"> Private void Page_Load (object sender, System. EventArgs e) { Response. Status = "301 Moved Permanently "; Response. AddHeader ("Location", "http: // www. Your Website address. cn/articles/301/"); } </Script> |
4. PHP 301 redirection code
The Code is as follows: |
Copy code |
Header ("HTTP/1.1 301 Moved Permanently "); Header ("Location: http: // www. Your Website address. cn/articles/301 /"); Exit (); |
5. The 301 redirection code in CGI Perl
The Code is as follows: |
Copy code |
$ Q = new CGI; Print $ q-> redirect ("http: // www. Your Website address-url, com /"); |
6. 301 redirection code under JSP
The Code is as follows: |
Copy code |
<% Response. setStatus (301 ); Response. setHeader ("Location", "http: // www. Your Website address. cn /"); Response. setHeader ("Connection", "close "); %> |
Jump code first
The website port is not used for the time being. Generally, port 80 is used. If some websites have pages with different ports, you need to debug the port code before using it.
The Code is as follows: |
Copy code |
<? Php $ Dest_host = "www. Old network address. com"; // declare a variable $ dest_host to store the URL to jump $ Url = $ _ SERVER ['request _ URI ']; // declare a variable $ url to store the host address and url of the current website. $ Http = (isset ($ _ SERVER ['https']) & $ _ SERVER ['https']! = 'Off ')? 'Https: // ': 'http: //'; // declare the variable $ http storage protocol // $ Port = $ _ SERVER ['server _ port'] = '80 ′?" : '$ _ SERVER ['server _ port']; // website PORT $ Url = $ http. $ dest_host. $ url; // merged address Switch ($ _ SERVER ['HTTP _ host']) { Case "www. Website address. cn": // If the obtained host is www. Website address. cn Header ('HTTP/1.1 301 Moved Permanently '); // load 301 Header ("location:". $ url ); Break; Case "website address. cn": // or the website address. cn Header ('HTTP/1.1 301 Moved Permanently '); // load 301 Header ("location:". $ url ); Break; } ?> |