Rewrite question mark

Topics: Developer Forum, User Forum
Jan 25, 2010 at 2:18 PM

hi,

I am rewriting URL's using the following line:

RewriteRule  ^/([^\.]*)$  /Page.aspx?urlTerm=$1

the problem is that I am having problem with question marks. For example I am getting error when trying to rewrite "how are you?"

 

I'll appreciate any help.

 

 

Coordinator
Jan 25, 2010 at 10:23 PM

please explain what you really want to do.  I don't think you are trying to rewrite "how are you?" 

The [QSA] flag may help.

 

Jan 26, 2010 at 8:08 AM

Thanks for your reply,

 

I am using the code:  RewriteRule  ^/([^\.]*)$  /Page.aspx?urlTerm=$1

I am passing part of the URL to '$1' parameter. For example for the URL 'http://mysite.com/money' the regX will catch the term 'money'  and pass it to the parameter so I get 'Page.aspx?urlTerm=money' that's how I am rewriting the URL. The problem is with question marks, when I have question mark in the URL ('http://mysite.com/money?') the regX does not catch 'money?'.

 

I hope I manage to explain it.

Thanks,

Eyal.

Coordinator
Jan 27, 2010 at 1:06 AM
Edited Jan 27, 2010 at 2:47 AM

According to IETF RFC 3986, there is a strict requirement that URIs may contain at most one ? .  It is recognized as a separator between what that RFC calls the "hierarchical path" and the "query part" of the URI.  If a query parameter itself is to include a value that has a question-mark, then that question-mark must be URL encoded, according to the RFC.

URL Status comments
http://myserver/money valid hierarchical path: /money
query params: (none)
http://myserver/money? valid hierarchical path: /money
query params: (empty)
http://myserver/money%3F valid hierarchical path: /money%3F
query params: (none)
http://myserver/Page.aspx? valid hierarchical path: /Page.aspx
query params: (empty)
http://myserver/Page.aspx?urlTerm valid hierarchical path: /Page.aspx
query params: name=urlTerm, value=(none)
http://myserver/Page.aspx?urlTerm= valid hierarchical path: /Page.aspx
query params: name=urlTerm, value=''
http://myserver/Page.aspx?urlTerm=money valid hierarchical path: /Page.aspx
query params: name=urlTerm,  value='money'
http://myserver/Page.aspx?urlTerm=money? INVALID Two ? in the URL = invalid
http://myserver/Page.aspx?urlTerm=money%3F valid The 2nd ? in the URL is encoded as %3F
hierarchical path: /Page.aspx
query params: name=urlTerm, value='money%3F'

 Your rule is firing, but the URL is being normalized, somewhere, to eliminate the trailing question mark. 

Ok, my next question - what is the significance of the question mark?   If it is significant, and is not to be interpreted as the query separator, you can encode it to %3F.   In a web page you can do this with a call to the Javascript escape() function.

 

Jan 27, 2010 at 8:25 AM

Cheeso, thank you very much for your help.