Use
toupper internal
rewrite map.
Here is an example. Let us assume you want to capitalize the first letter of the
jurisdiction_id query string parameter:
Code:
RewriteMap toupper int:toupper
RewriteCond %{QUERY_STRING} ^&*jurisdiction_id=([^&])([^&]*)
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%1}%2/services/$1.xml [NC,L]
However, that will only work if
jurisdiction_id is the only parameter. Let's fix that by matching both cases (at the beginning, and at elsewhere, in the query string):
Code:
RewriteMap toupper int:toupper
RewriteCond %{QUERY_STRING} ^jurisdiction_id=([^&])([^&]*) [OR]
RewriteCond %{QUERY_STRING} &jurisdiction_id=([^&])([^&]*)
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%1}%2/services/$1.xml [NC,L]
The above converts the initial letter to uppercase, but retains the rest of the value as-is. If you want to
canonicalize the
jurisdiction_id , then lowercase the rest of it:
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING} ^jurisdiction_id=([^&])([^&]*) [OR]
RewriteCond %{QUERY_STRING} &jurisdiction_id=([^&])([^&]*)
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%1}${tolower:%2}/services/$1.xml [NC,L]
If you also want to make sure the final XML file name is in lower case, use
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING} ^jurisdiction_id=([^&])([^&]*) [OR]
RewriteCond %{QUERY_STRING} &jurisdiction_id=([^&])([^&]*)
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%1}${tolower:%2}/services/${tolower:$1}.xml [NC,L]
When you have one query parameter, you usually end up having another, at least occasionally. It is therefore a good idea to retain the rest of the query parameters, too. If the target is a script, it can then utilize the parameters; otherwise the query parameters are ignored. In any case, they do no harm, and the extra processing time taken should be truly neglible.
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING} ^()&*jurisdiction_id=([^&])([^&]*)(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^&*(.+)&+jurisdiction_id=([^&])([^&]*)(.*)$
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%2}${tolower:%3}/services/${tolower:$1}.xml?%1%4 [NC,L]
Note that since either condition may match, we use an empty pair of parentheses in the first one, so that both conditions have (logically) the same referable parts.
The above removes the jurisdiction_id from the query string. If you wish to retain it also, in its original form, use
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING} ^()&*jurisdiction_id=([^&])([^&]*)(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^&*(.+)&+jurisdiction_id=([^&])([^&]*)(.*)$
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%2}${tolower:%3}/services/${tolower:$1}.xml?jurisdiction_id=%2%3&%1%4 [NC,L]
or, to retain it in canonicalized form:
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING} ^()&*jurisdiction_id=([^&])([^&]*)(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^&*(.+)&+jurisdiction_id=([^&])([^&]*)(.*)$
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%2}${tolower:%3}/services/${tolower:$1}.xml?jurisdiction_id=${toupper:%2}${tolower:%3}&%1%4 [NC,L]
I hope you find the step-wise development of the solution informative,