insaner
insaner

Reputation: 1705

mod_rewrite in .htaccess, go/*, go?, go?/* work, but go/?* doesn't

I tried going through some of the mod_rewrite questions on the site, but didn't find an answer to my problem (the fact that most questions were titled "mod_rewrite doesn't work" didn't help make that task any easier, hopefully my title is a little more helpful).

this is the content of my /somepath/.htaccess:

RewriteEngine On
RewriteRule ^go/(.*) /cgi-bin/goto.cgi?$1
    # ^^^ WORKS: /somepath/go/200001..
RewriteRule ^go?(.*) /cgi-bin/goto.cgi$1
    # ^^^ WORKS:  /somepath/go?200001..


ErrorDocument 404 /cgi-bin/goto.cgi?error404

In testing, I made goto.cgi simply return $ENV{QUERY_STRING}, $ENV{QUERY_STRING_UNESCAPED} and $ENV{PATH_INFO}. Currently, the above rules mean that I am getting the QUERY_STRING passed on correctly when the urls:

/somepath/go/200001
/somepath/go?200001
/somepath/go?/200001

are accessed, but not when

/somepath/go/?200001

is accessed, in which case $ENV{QUERY_STRING}, $ENV{QUERY_STRING_UNESCAPED} and $ENV{PATH_INFO} are empty.

So the question is, what rule can I use so that

/somepath/go/?200001

gives my script the ?200001 or even /?200001 part back?

Upvotes: 0

Views: 64

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799024

The first rule is destroying the query string of the example that fails, since $1 will be empty and an empty query string in the substitution removes any existing query string.

And the second rule is gibberish.

RewriteRule ^go/(.+)$ /cgi-bin/goto.cgi?$1
RewriteRule ^go/?$ /cgi-bin/goto.cgi

Upvotes: 1

Related Questions