PDA

View Full Version : Mod_rewrite 301 help?



Chris
08-09-2007, 08:57 AM
http://www.cbswords.com/product_info.php/cPath/38/products_id/232

Alright, for some reason way back when Google indexed my site with a weird session ID in it (it isn't even complete) then people started linking to those pages, which helped Google to continued to indexing these pages.

If you visit a link such as above that sessionID is removed for all further site browsing, but I'd like to craft a 301 redirect to stop Google from indexing such URLs once and for all.

So,, ideally I'd like a little RedirectMatch statement that says ...

Any url that ends in ?osCsid=459e87db should be forwarded to a URL that is exactly the same, minus the "?osCsid=459e87db" from the end.

I'm not quite comfortable enough with regular expressions to do this I think. Any gurus wanna lend a hand?

I think it'd be something like this:

RedirectMatch 301 ^(.*)osCsid=459e87db$ $1

But that isn't working for me.

Nico
08-09-2007, 11:51 AM
Hi Chris,

Using Mod_Rewrite this works for me:
RewriteCond %{QUERY_STRING} osCsid=459e87db
RewriteRule ^(.*)$ http://www.yoursite.com/$1? [R=301,L]

But i don't know how to do it with mod_alias (RedirectMatch).

Also, from this page (http://httpd.apache.org/docs/2.0/mod/mod_alias.html):
"mod_alias is designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_rewrite."

Chris
08-09-2007, 02:09 PM
I realized I posted the wrong URL I wanted to fix, here is the right url

www.cbswords.com/product_info.php/cPath/38/products_id/232?osCsid=459e87db

So it is the entire query string I want to remove. Will yours do that Nico?

Nico
08-09-2007, 02:37 PM
Yes, i think so. My example it's supposed to remove everything after the "?", if it finds the matching keyword in the Query String.

I put my test file online...
http://www.famousdeaddb.com/test/hola.php?osCsid=459e87db&variable1=1&variable2=2
That link will remove everything in the Query String.

And this one won't remove anything...http://www.famousdeaddb.com/test/hola.php?variable1=1&variable2=2

Does that help?

Chris
08-09-2007, 04:36 PM
It worked, thanks for your help Nico.

One of the links got in MacWorld and a couple other heavy technology blogs, so I didn't want all that link popularity go to waste.

Nico
08-09-2007, 04:46 PM
No problem!