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: |
Copy code |
| <? Php Header ("Location: http://www.bKjia. c0m /"); ?> |
However, the returned status code is 302.
If you want to achieve 301 redirection, you need to set the status code before
| The Code is as follows: |
Copy code |
| <? Php Header ("HTTP/1.1 301 Moved Permanently "); Header ("Location: http://www.bKjia. c0m /"); ?> |
Simpler PHP jump 301 code
| The Code is as follows: |
Copy code |
| <? Php $ Urlto = 'HTTP: // www. bKjia. c0m /'; Header ('location: '. $ urlto, TRUE, 301 ); ?> |
Possible problems
Warning: Cannot modify header information-headers already sent by changing the file encoding to the 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.