Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

another odd htaccess query string problem

3:38 pm on Jun 28, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 31, 2004
votes: 0

I recently posted a query on removing url's with negative query strings in forum92/6346.htm. That was resolved with correct syntax and a 410 thanks to jd.

I now need to 404 positive query strings which do not end in zero and also 301 one in a particular case which has a zero only. The 404 vs 410 is used because these addresses may be used in the future so we do not want to 410 them permanently.

So far, some of the code works but breaks other things:

RewriteCond %{QUERY_STRING} offset=[1] [OR]
RewriteCond %{QUERY_STRING} offset=[2] [OR]
RewriteCond %{QUERY_STRING} offset=[9]
RewriteRule ^(.*) [R=404]

This works to a point. It does 404 anything ending in 1,2, etc. However, valid addresses such as offset=20 are also being 404'ed because the 2 is in the query string. Have also tried various regex combinations for above without success.

To complicate this a bit further there is one instance where a single query string = 0 needs to be 301 not 404:

sub-dir/category.php?offset=0 is the same as sub-dir/category.php which is causing duplicate content issues. So the offset=0 needs to 301 redirect to the appropriate sub-dir/category.php.

In 1st case above the 404 brings up an incorrect "Not Found" message:

The requested URL /[R=404] was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. (I have not got to the ErrorDocument work yet.)




3:51 pm on June 28, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

You must provide a substitution URL in any RewriteRule; Use the "-" token if you do not wish to change the existing URL. Also, [R=404] is not supported.

Try something like this:

# Match any number of digits, not ending in zero
RewriteCond %{QUERY_STRING} offset=[0-9]*[1-9]
# Rewrite to nonexistent filepath to force 404 response
RewriteRule ^(.*) /path_that_does_not_exist.txt [L]

Ge that working, and then the offset=0 case will be a trivial one-rule addition.



Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members