Allow question marks without asking for "?" in URL / URI without encoding

Customization

we have the following directory structure on our HTTP / web server:

/questions/who?/
/questions/what?/
/happy? part. 01/
/happy? yet?/
/happy? yet? again? really?!/

Question

my question is: is it possible for corresponding URIs / URLs with undefined / unencoded question marks ( ?) to resolve correctly? for example, the URL http://test.org/happy? part. 01/will be resolved on /happy? part. 01/the server. due to the ?meaning of the query string, this was a problem for me.

background / research

as expected by default, Apache treats the first ?as the beginning of the query string. therefore, out of the box, the URL http://test.org/happy? part. 01/will be converted to a URI path /happyand a query string part.01/, which will result in 404 because the path /happydoes not exist.

/, , URL-, , ? , .

, HTTP- URL- .

, .. URI (, http://test.org/happy? part. 01/ http://test.org/happy%3F%20part.%2001/, , , URI: RFC2396 RFC3986). URL-, URL- .

, , :

RewriteRule ([^\?]*?)\?([^\?]*?) $1\?$2 [NE,N]

? URL- unescaped. , ( ) URL-, ?, ? %3F. , $2 . , \? , , - .

, ? %{THE_REQUEST}, Apache /RewriteRules. :

RewriteCond %{THE_REQUEST} ^[A-Z]+\ \/([^\?]*?)\?([^\?]*?)\/?\ HTTP
RewriteRule ^(.*?)\?(.*?)$ $1\?$2 [NE,N]

RewriteCond URI ?, %2 RewriteRule Internal Server Error, , , URL ?.

, %{QUERY_STRING} [QSA], .

, .

+4
1

:

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ /$1\%3F%{QUERY_STRING} [L,NE]

EDIT:

:

RewriteCond %{QUERY_STRING} ^(.*)\?(.*)$
RewriteRule ^(.*)$ /$1?%1\%3F%2 [L]

RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ /$1\%3F%{QUERY_STRING}? [L,NE]
+2

All Articles