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...