Forum Moderators: phranque

Message Too Old, No Replies

rewrite blaa=foo except /?ProductID=foo

google yahoo random query strings duplicate urls

         

appi2

8:31 am on Dec 1, 2006 (gmt 0)

10+ Year Member



heeeelp
How can I use rewrite rules to stop the server returning a 200 ok for any query string
except for the ones I want to return 200 ok?

eg
These are fine, and should be allowed
www.example.com/shop/?ProductID=variable
www.example.com/shop/
www.example.com/

Don't want random queries from google yahoo returning 200 ok
eg from log files google wants
www.example.com/shop/?A=756&B=56
www.example.com/CFID=65850&CFTOKEN=8789
or any other thing yahoo or google hits the site with.

I can match any query string with

RewriteCond %{QUERY_STRING} ^.+$
RewriteRule ^(.*) http:// www.example.com/pita.php
#pita.php doesnt exist so server returns 404 error

but the above would also catch www.example.com/shop/?ProductID=variable

Trying to do...
if not /?ProductID=foo or / then 404

Using
Apache/1.3.27
.htaccess in root folder.

Other rewrite rules already in htaccess

RewriteEngine On
###
#Redirect "/index.html php" or "/foo/.../index.html php" to "/" or "/foo/.../"
#This also works for "index.php?ProductID=foo" to "/?ProductID=foo"
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /[^.]*\index\.(php¦html)[^\ ]*\ HTTP/
RewriteRule ^(.*)index\.(php¦html)$ http:// www.example.com/$1 [R=301,L]

I need sleep.

jdMorgan

3:35 pm on Dec 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bit of a logic mish-mash, really...

Trying to do...
if not /?ProductID=foo or / then 404

 # Force 404 response if query is non-blank and contains non-ProductID parameters
# IF query is non-blank
RewriteCond %{QUERY_STRING} .
# AND IF query is NOT "ProductID=<letters, numbers, or hyphen>"
RewriteCond %{QUERY_STRING} !^ProductID=[A-Za-z0-9\-]*$
# THEN rewrite to non-existent file to force a 404
RewriteRule .* /path_that_does_not_exist [L]

Alternatively, use a 410-Gone response:

# Force 404 if non-blank query contains non-ProductID query
# IF query is non-blank
RewriteCond %{QUERY_STRING} .
# AND IF query is NOT "ProductID=<letters, numbers, or hyphen>"
RewriteCond %{QUERY_STRING} !^ProductID=[A-Za-z0-9\-]*$
# THEN force a 410-Gone response
RewriteRule .* - [G]

Jim

appi2

6:37 pm on Dec 1, 2006 (gmt 0)

10+ Year Member



Thanks jim
Tried several other forms of dodgy logic in a quest to not to have to ask!
This line makes me sooo happy.
RewriteCond %{QUERY_STRING} .

cheers.