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]
Introduction to Yoast SEO webinar
Discover how to effectively use the Yoast SEO plugin. Get hands-on tips for setup, content optimization, and more.
All Yoast SEO WebinarsBaltic-Nordic SEO Summit
Team Yoast is Attending, Sponsoring, Yoast Booth at Baltic-Nordic SEO Summit! Click through to see who will be there, what we will do, and more!
See where you can find us nextPodcast
Add main headingMain heading optional second line Gain invaluable SEO insights and expert analysis One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim […]
All Yoast SEO Podcasts
Discussion (19)