Forum Moderators: phranque

Message Too Old, No Replies

removing ? urls

         

santapaws

8:04 pm on Jun 4, 2010 (gmt 0)

10+ Year Member



What is the best way to prevent the server allowing any variable for urls with a question mark. i.e. to stop things like domnain.com/?anythinguwant.html from being indexed. Thanks.

g1smd

9:02 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you want those requests redirected to the same URL path but without the appended parameters, or do you want to return a HTTP 404 status instead?

Or something else?

santapaws

9:17 pm on Jun 4, 2010 (gmt 0)

10+ Year Member



404 is what im looking to return. Thanks.

g1smd

9:34 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What have you tried?

It's likely two lines of code. One will be a RewriteCond looking at QUERY_STRING and matching "non blank", and the other will be a RewriteRule internally rewriting to a non-existent internal filepath and hence triggering the 404 ErrorDocument response. Round it all off with the [L] flag as usual.

jdMorgan

11:12 pm on Jun 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Taken mostly from [webmasterworld.com...]

# Rewrite requests with any query string appended to nonexistent filepath (to force a 404)
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /[^?\ ]*\?[^\ ]*\ HTTP/
RewriteRule ^ nonexistent-filepath.hmtl [L]

Jim

santapaws

8:59 am on Jun 5, 2010 (gmt 0)

10+ Year Member



jd your a hero as usual, thanks.