Forum Moderators: phranque
I have been working on getting an unusual PHPSess string removed from the front page of my site. I believe this may be causing duplicate issues. It's a tricky one and unfortunatley I haven't been able to get it working.
I need to 301 redirect the following string to the frontpage:
www.site.com/?PHPSESSID=f9f2770d591366bc
to just www.site.com/
Using something along the lines of the following did not work:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^PHPSESSID=f9f2770d591366bc$
RewriteRule ^/$ http://www.example.com/?productid=100002&cat=&page=1 [R=301,L]
Can anyone pinpoint an error in the above?
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^PHPSESSID=f9f2770d591366bc$
RewriteRule [b]^$[/b] http://www.example.com/?productid=100002&cat=&page=1 [R=301,L]
In other words, it remove the session ID and then creates the productid=100002, blank category, and page=1 name/value pairs in the query string.
So, it will work for only the one session ID, and will always set your query string to te value specified, regardless of what it might have contained in addition to the session ID.
I suspect that what you are really trying to do is to remove the session ID but preserve the other parameters, and that you'd like to remove *any* session ID, and not just the one exact session ID number you've specified above.
I also presume you only want to remove the session ID for search engine robots, since your site probably won't work if you remove them unconditionally.
In that case, you'd want something more like:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} Slurp [OR]
RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
RewriteCond %{HTTP_USER_AGENT} Teoma
RewriteCond %{QUERY_STRING} ^(([^&]+&)+)*PHPSESSID=[0-9a-f]*&(.*)$
RewriteRule ^$ http://www.example.com/?%1%3 [R=301,L]
Be aware that this whole rewriterule redirect method is an after-the-fact "repair" approach; You should modify the script(s) you are using to make sure that recognized search engine spiders are never given a session ID in the first place, and use the code above only to repair the "messy" search results that you have now.
Jim
I actually posted some partly incorrect code. What I MEANT to type was:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^PHPSESSID=f9f2770d591366bc$
RewriteRule ^$ http://www.example.com/ [R=301,L]
As you can see, all I wanted to do was to refer that exact PHPSESSID to a domain, and nothing further. I must have had a Sunday morning hangover :-/
HOWEVER, when uploaded and accessed, the page is not responding (perhaps going into an endless loop?).
RewriteCond %{QUERY_STRING} ^PHPSESSID=f9f2770d591366bc$
RewriteRule ^$ http://www.example.co[b]m/?[/b] [R=301,L]
Jim