The 301 jump tells the visitor that the page has always reached a new page. in php, we use the 301 jump function to send the 301 status code to the browser, and then implement the page jump.
The 301 jump tells the visitor that the page has always reached a new page. in php, we use the 301 jump function to send the 301 status code to the browser, and then implement the page jump.
PHP code-only jump,The code is as follows:
- Header ("Location: http://www.phpfensi.com /");
- ?>
However, the returned status code is 302. if you want to perform a 301 redirect, you must set the status code as follows:
- Header ("HTTP/1.1 301 Moved Permanently ");
- Header ("Location: http://www.phpfensi.com /");
- ?>
The code for a simpler PHP jump to code 301 is as follows:
- $ Urlto = 'http: // www.phpfensi.com /';
- Header ('Location: '. $ urlto, TRUE, 301 );
- ?>
Possible problems
Warning: Cannot modify header information-headers already sent by change the file encoding to UTF-8 without BOM format, can solve this problem, if there is still a problem, check whether the string variable is defined before the code. delete the variable and try again.
Appendix: differences between 30 * return status codes
301,302 is an HTTP status code, indicating that a URL has been transferred. The difference is:
1.301 redirect: 301 represents permanent transfer (Permanently Moved)
2.302 redirect: 302 indicates temporary transfer (Temporarily Moved)
What are the advantages or problems of these two transfer methods?
301 redirection is the best way for seo search engines to be friendly after a webpage address is changed. as long as it is not temporarily moved, we recommend that you use 301 for address conversion.
302 redirection is a temporary transfer.