Forum Moderators: Robert Charlton & goodroi
to put it in a different perspective, if your URL can be dynamically changed to another URL which does not reflect the actual keyword you programmed for your URL and still resolves as a 200 header found, you've got a problem.
[edited by: tedster at 2:56 pm (utc) on May 8, 2010]
In addition, best practices suggest that a full URL --protocol, domain, and URL-path-- should be used in any rule intended to invoke an external redirect.
### DROP KNOWN BAD Qs
RewriteCond %{QUERY_STRING} ^from.*$ [OR]
RewriteCond %{QUERY_STRING} ^ref.*$ [OR]
RewriteCond %{QUERY_STRING} ^q=$
RewriteRule ^/(.*) http://www.example.com/$1? [R=301,L]
### DROP ALL Qs Except Select Folders/Files
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{REQUEST_URI} !^/search$
RewriteCond %{REQUEST_URI} !^/widgets/search.html$
RewriteCond %{REQUEST_URI} !^/stats.*$
RewriteCond %{REQUEST_URI} !^/__utm.gif$
RewriteRule ^/(.*) http://www.example.com/$1? [R=301,L]
RewriteBase /
RewriteCond %{QUERY_STRING} ^([^&]*&)*searchterm=[^&]* [NC]
RewriteRule .* - [R=404,L]
RewriteBase /
RewriteCond %{QUERY_STRING} ^([^&]*&)*searchterm=[^&]* [NC]
RewriteRule .* /some-path-that-you-know-will-never-exist.html? [L]
jdMOrgan.. I was able to combine two of your examples into a series of rules that work perfectly for me:[webmasterworld.com ]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?]*)\?
RewriteCond %{QUERY_STRING} !^SID=
RewriteCond %{QUERY_STRING} !^np=
RewriteRule !\.php$ http://example.com/%1? [R=301,L]
Anyway, let me state what the above does... unless a query string has ?SID= or ?np= it removes the query string and the question mark with a 301 redirect, for both bots & users (unless it's a .php page).
Post #:4131405 has the answer you require.
Internally rewrite to a /non-existent-path and the ErrorDocument mechanism should directly return the correct 404 header and the content of the error page.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^?]*)\?
RewriteCond %{query_string} !^option= #This allows genuine urls with a query string to be found.
RewriteRule !\.php$ http://www.example.com/%1? [R=301,L]