301 redirect means "moved permanently"
Every website has to have SEO onpage. That means sometimes you need 301 redirects, when you want to replace some url with a new url. How do you get 301 redirect in PHP? Using header function.
Here is a simple example:
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '.$new_location);
exit();
This code must be used in the old file, that you want to remove from search engines. $new_location is the new path where the script is being redirected. exit() must be used to stop the script.
Remember to not display anything (any HTML or other text sent to browser) before calling header() function. Or if you do, you can use output buffering to clear the output.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment