PHPSESSID in your URL? Learn to 301 redirect them with PHP
I’m doing some work on a site which has like 4,500 pages indexed with a PHPSESSID in the URL, causing some major duplicate content problems. I got the server admin to disable the PHPSESSID’s by adding the following to the vhost config:
[code]php_value session.use_trans_sid 0
php_value session.use_only_cookies 1[/code]
I also wanted Google to get a clean URL when it decided to spider one of the old URL’s again, and didn’t have access to mod_rewrite, so I redirected them with some PHP. The solution is quite simple:
[code]if (isset($_GET[‘PHPSESSID’])) {
$requesturi = preg_replace(‘/?PHPSESSID=[^&]+/’,””,$_SERVER[‘REQUEST_URI’]);
$requesturi = preg_replace(‘/&PHPSESSID=[^&]+/’,””,$requesturi);
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://”.$_SERVER[‘HTTP_HOST’].$requesturi);
exit;
}[/code]
Coming up next!
-
Event
International Search Summit 2024
November 14, 2024 Team Yoast is at Attending, Speaking International Search Summit 2024! Click through to see who will be there, what we will do, and more! See where you can find us next » -
SEO webinar
Webinar: How to start with SEO (November 19, 2024)
19 November 2024 Learn how to start your SEO journey the right way with our free webinar. Get practical tips and answers to all your questions in the live Q&A! All Yoast SEO webinars »
19 Responses to PHPSESSID in your URL? Learn to 301 redirect them with PHP