Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite Question: Processing the "?" symbol

.htaccess question mark

         

NeedExpertHelp

10:17 am on Sep 22, 2009 (gmt 0)

10+ Year Member



Hello everyone, I'm new to WW and had a question about the "?" in .htaccess.

I'm using the following RewriteRule that works great but it does not seem to process the "?" symbol (it seems to completely ignore it):

RewriteEngine On
RewriteRule ^([a-zA-Z][a-zA-Z])-([a-zA-Z][a-zA-Z])/([^/]+)$ /do.php?cat=$1&cat=$2&cat=$3 [L]

For example, if I go to mysite.com/aa-bb/question?, it processes it as:

do.php?cat1=aa&cat2=bb&name=question

and not:

do.php?cat1=aa&cat2=bb&name=question?

Yet if I go directly to:

mysite.com/do.php?cat1=aa&cat2=bb&name=question?

(without making use of the .htaccess rule), it processes the "?" without problems, so I assume the issue is with the .htaccess RewriteRule.

Any ideas on how I can get it to process the "?" instead of ignoring it? (It also ignores anything AFTER the "?" mark, which I don't want either).

Just to be clear, by "process" I mean that if I go to mysite.com/aa-bb/question? and do a $_GET['name'], I would like it to "get" the "?" symbol as well (e.g. I'd like $_GET['name'] to return "question?" and not just "question".)

Maybe one of these resources will lead us on the right track (I couldn't make too much sense out of them, but they seem relevant):

[ask.metafilter.com...]

[webmasterworld.com...]

[forums.devshed.com...]

[evisibility.com...]

[webmasterworld.com...]

Thanks, I appreciate your help!

NeedExpertHelp

2:22 pm on Sep 24, 2009 (gmt 0)

10+ Year Member



Thanks for that.

How do I escape the "?" in the sequence BEFORE putting it into the URL?

Also, are you sure the .htaccess rule is:

RewriteRule ^[a-z]{2}-[a-z]{2}/ /do.php [L]

What about the variables cat1, cat2, and name?

Thanks again.

jdMorgan

3:16 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The point is that the rule doesn't need to pass the variables to the script as a query string. The script itself can be modified, as posted by vincevincevince, to directly-access them by looking at a server variable that is similar to THE_REQUEST.

vincevincevince also provided the necessary correction to the PHP regex pattern above.

Jim

NeedExpertHelp

8:38 am on Sep 25, 2009 (gmt 0)

10+ Year Member



Vince: That worked, thank you very much! I would also say I prefer this solution vs. the .htaccess solution as it seems more straightforward and does not complicate the .htaccess too much (which, as Jim mentioned, is always a risk).

Jim: I found out what the problem was with the main index form not properly encoding non-standard characters. You were right, it was not the .htaccess, but it was also not the forms (as they were identical). After some thorough analysis, the problem was simply that the main index page did not have any meta character encoding in the html while the do.php page had utf-8 encoding, that's what was messing up the encoding of non-standard chars when the form was sent from the main index page and why it was working when the same form was being sent from do.php.

Jim and Vince (and g1smd), thank you all very much for your help, expertise, and patience. I greatly appreciate it.

I'm very pleased and relieved that we were able to resolve this completely and thoroughly with the best solution possible. Big thumbs up from me. :)

This 33 message thread spans 2 pages: 33