Forum Moderators: phranque

Message Too Old, No Replies

How do I remove parameters with mod_rewrite

         

friskybits

8:06 am on Jul 6, 2005 (gmt 0)

10+ Year Member



Hi,

My home page URL has been indexed by Google in the form http://www.example.co.uk/?adCode=melon. I want to get rid of the /?adCode=melon bit and send a 301 redirect to Google so that my listing becomes http://www.example.co.uk.

I tried doing this with Redirect but it doesn't seem to work for form parameters. Some initial investigation leads me to believe that I need to use mod_rewrite with a RewriteCond of 'QUERY_STRING'. I've had a few goes at this but haven't managed to fix the problem.

Does anyone know how to write a RewriteRule to do this?

Thanks,

Frisky Bits

[edited by: jdMorgan at 6:03 pm (utc) on July 6, 2005]
[edit reason] Removed specifics per TOS. [/edit]

jdMorgan

6:05 pm on Jul 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This recent thread [webmasterworld.com] may help you get started in the right direction. For technical references and information about this forum, please review our Forum Charter.

Jim

friskybits

7:32 am on Jul 7, 2005 (gmt 0)

10+ Year Member



Thanks Jim,

this is what I have come up with. It seems to work but I'm not totally sure why.

RewriteEngine On
RewriteLog logs/rewrite.log
RewriteLogLevel 9
RewriteCond %{QUERY_STRING} ^(.*)adCode(.*)$
RewriteRule ^(.*)$ http://www.example.co.uk? [R=301,L]

Does it look OK to you?

Regards,

Martin

[edited by: jdMorgan at 6:13 pm (utc) on July 7, 2005]
[edit reason] Obscured URL per Terms of Service. [/edit]

jdMorgan

6:12 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you simply want to delete the entire query string and redirect to your main page (as your code above does), you can shorten that to:

RewriteEngine On
RewriteLog logs/rewrite.log
# RewriteLogLevel 9
RewriteCond %{QUERY_STRING} adCode
RewriteRule .* http://www.example.co.uk/? [R=301,L]

Do not leave that "LogLevel 9" in there on a live server -- This will significantly slow down your server. Comment it out as shown, or delete it entirely.

If you want to retain some of the query parameters or retain the requested page name, then the code will require modification.

Jim

friskybits

8:11 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



Thanks Jim,

I knew that there would be a simplification but I didn't know what.

Many thanks for your help.

Regards,

Martin