PHP Tutorial: how to implement 301 redirection _ PHP Tutorial

Source: Internet
Author: User
PHP Tutorial: how to implement 301 redirection. What is 301 redirection? 301 redirection means that when your website address changes, such as domain name change or website revision, you want a visitor or search engine to jump to the new address to access what is 301 redirection? 301 redirection means that when your website address changes, such as domain name change or website revision, you want visitors or search engines to jump to a new address to access the website, in this case, you need to perform 301 redirection. There are many ways to implement 301 Redirection. This article mainly introduces how PHP programs implement 301 redirection.

PHP code redirection 301


$ The_host = $ _ SERVER ['http _ host']; // mark the current domain name

$ Request_url = isset ($ _ SERVER ['request _ URI '])? $ _ SERVER ['request _ URI ']: ''; // judge the part after the address

If ($ the_host! = 'Www .bkjia.com ') // no domain name address changed

{Header ('http/1.1 301 Moved Permanently '); // A 301 error is prompted.

Header ('Location: http://www.bkjia.com/'.w.request_url); // add a new domain name address

}

?>

In which file is the 301 redirection command added?

Add the 301 redirection command to the. htaccess file and use the "mod_rewrite" technology.

Example:

RewriteEngine on

RewriteRule ^ (. *) $ http://www.bkjia.com/#1 [R = 301, L]

Why? 301 redirection means that when your website address changes, such as domain name change or website revision, you want visitors or search engines to jump to the new address to access the website...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.