1

I have a website for which I would like to redirect the following requests :

www.example.com/wwv_flow.js_messages?p_app_id=103&p_lang=fr&p_version=19.1.0.00.15-51560988

To :

www.example.com/apex/app/wwv_flow.js_messages?p_app_id=103&p_lang=fr&p_version=19.1.0.00.15-51560988

Basically, the rule is whenever the requests starts with wwv, then add apex/app/ right before and keep everything the same.

In my .htaccess file I tried :

RewriteCond %{HOST_NAME} ^wwv([.]+)/?$
RewriteRule ^wwv([.]+)/?$ ./apex/app/$1 [L]

But it's not working. First the condition doesn't work, and second the redirection fails due to the special characters in the URL : ?, &, =

Does anyone know how to solve that please?

3

1 Answer 1

1
RewriteCond %{HOST_NAME} ^wwv([.]+)/?$
RewriteRule ^wwv([.]+)/?$ ./apex/app/$1 [L]

This rule block will never match the stated URL for several reasons:

  • The regex [.] (a dot inside a character class) matches a literal dot, not "any character". The character class negates the dots special meaning. So, [.]+ matches 1 or more dots. You should remove the square brackets, ie. .+ in order to match 1 or more "any character". Although to match any request that simply "starts with wwv" (as stated in your question), the entire regex can be simplified to ^wwv(.*).
  • In the RewriteCond directive it looks like you are trying to match the wwv part against the hostname. In your example URL wwv is part of the URL-path, not the hostname.
  • There is no such variable HOST_NAME. Perhaps you meant HTTP_HOST? However, that is still incorrect (as mentioned above). (You should have used REQUEST_URI - in order to match against the URl-path - but then the regex would still have been incorrect. However, this condition is superfluous anyway.)

The RewriteCond (condition) directive is not required here. (Repeating the same comparison in the RewriteCond that you are performing in the RewriteRule directive is superfluous and just results in more "work".)

The ./ prefix on the RewriteRule substitution is not required here and should be removed.

Note that the RewriteRule pattern matches against the URL-path only. This notably excludes the query string. (If you specifically needed to match against the query string then you would need a RewriteCond directive that matched against the QUERY_STRING server variable. But this is not required here.)

First the condition doesn't work, and second the redirection fails due to the special characters in the URL : ?, &, =

These aren't really "special characters" and they should not cause a problem here. It fails because it simply doesn't do anything (as noted above) - it doesn't match the requested URL.

The query string is passed through to the substitution by default, so there is nothing you need to do regarding the "special characters".

Solution

whenever the requests starts with wwv, then add apex/app/ right before and keep everything the same.

To perform the necessary "redirect" you would need something like the following:

RewriteRule ^wwv(.*) /apex/app/$1 [R=302,L]

The (.*) capturing subpattern matches the remainder of the URL-path, ie. _flow.js_messages in your example. And this is then referenced in the substitution with the $1 backreference.

As noted above, the query string (ie. p_app_id=103&p_lang=fr&p_version=19.1.0.00.15-51560988) is passed through to the substitution by default. There is nothing extra you need to do here.

Note that this is a 302 (temporary) redirect.

If you require an internal rewrite (as suggested by your code snippet) then remove the R flag. And optionally remove the slash prefix on the RewriteRule substitution (but this can depend on the value of RewriteBase - if any).

RewriteRule ^wwv(.*) apex/app/$1 [L]

Note that the order of these directives in .htaccess is important. If you have existing mod_rewrite directives, then this will likely need to go near the top.

You don't actually need mod_rewrite, if this is the only action you are performing. A mod_alias RedirectMatch would suffice. However, mod_rewrite would probably be necessary if you have existing mod_rewrite directives.

0

You must log in to answer this question.

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