0

I am in the process of redirecting a URL and I wanted to use the 'RewriteRule' directive when in the process of doing so.

I currently have a rule as follows:

 RewriteRule ^/application/web/reservation/index.jsp https://application.domain.com/application2/web/reservation/audioForm.zul [R,L]

However I also want this to work if a locale is added to the end of the first URL. It could be various different locales (never static), so I want the RewriteRule to take whatever comes after '.jsp' in the first URL and place it after '.zul' in the second.

For example something like:

RewriteRule ^/application/web/reservation/index.jsp(*)$ https://application.domain.com/application2/web/reservation/audioForm.zul$1 [R,L]

I believe I have the syntax wrong for the replacement portion:

(*)$ and $1 respectively

Just so you can see what the link looks like with the locale, I have placed an example below:

https://application.domain.com/application/web/reservation/index.jsp?locale=de-DE

I would want to place '?locale=de-DE' after .zul in the second URL.

Can anyone tell me what I am doing wrong? Any help would be greatly appreciated.

Best Regards

2 Answers 2

1

Actually your own answer is not correct.

To match a specific (specific word is important here) query string, such as the example you mention "?locale=de-DE'" you would need a RewriteCond doing it.

But in this specific case, since the target url is not specifying a query string, default behaviour from mod_rewrite is to append the original query string (whatever it was) to it unless you specify the QSD flag (query string discard).

So, briefly:

RewriteRule ^/application/web/reservation/index.jsp https://application.domain.com/application2/web/reservation/audioForm.zul [R,L]

or even:

RewriteRule ^/application/web/reservation/index.jsp$ https://application.domain.com/application2/web/reservation/audioForm.zul [R,L]

would match a request for:
"/application/web/reservation/index.jsp?whatever"
and would append whatever query string to the target you specified:
"https://application.domain.com/application2/web/reservation/audioForm.zul" because it does not specify a query string.

1
  • 1
    Thank you! The above way I did it seemed to work for me, but it does not seem to be the correct way to accomplish what I am looking to do based on your explanation. Let me test your method and see how it works. Mar 1, 2018 at 18:04
0

I actually figured it out after a couple hours of playing around and researching the mod_rewrite API.

Apache Module mod_rewrite - Apache HTTP Server

Instead of:

^/application/web/reservation/index.jsp(*)$

I used:

^/application/web/reservation/index.jsp(.*)
1
  • 1
    Yes, because mod_rewrite uses regular expressions and not globs. Mar 1, 2018 at 21:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .