I need to handle one query parameter specifically.
The url can look like the following:
https://example.com/?app=egov&map=1337
https://example.com/?app=egov&map=1337&showoptions=true
https://example.com/?app=egov&map=1337&showoptions=true&anotherparam=helloWorld
The redirect should point to
https://example.com/contextName/resources/apps/egov/index.html?map=1337
https://example.com/contextName/resources/apps/egov/index.html?map=1337&showoptions=true
https://example.com/contextName/resources/apps/egov/index.html?map=1337&anotherparam=helloWorld
As you can see, the app
-Parameter needs to be used as an URL-part; the others need to be used like traditional query-params.
I’ve figured out, how to implement the first part, where https://example.com/?app=egov
points to https://example.com/contextName/resources/apps/egov/index.html
using the following
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^app=(.+)
RewriteRule ^/$ "/contextName/resources/apps/%1/index.html" [R,L,QSA]
but I’m struggeling how to realize the correct handling of the other params.
2
Answers
With your shown samples, please try following htaccess Rules file. Please make sure to clear your browser cache before testing your URLs.
All of your URLs uri part is NULL, so rules are written based on that.
All these combination of query string can be handled by a single rule loke this:
RewriteCond
matchesapp
query parameter and captures it in%1
while rest of the query string after&
is captured in%2
.