0

I am using Apache web server "httpd-2.4.25-win64-VC14" which is integrated with JBoss. The Port redirect is working properly. Now i want to replace URL based on some condition let's say if URL contains 'Mobile' then i want to replace it with 'Mobile/web' and forward it.

For this I am using <Directory> tag enclosed within <VirtualHost> tag. Now most the online references I am finding are having URL's in front of tag such as 'var/www/example' but I want to redirect based on localhost as I am running Jboss locallly.

So how should I write the tag contents , i tried with the below

<VirtualHost *:80>          
    <Directory /var/www/example/>
        Allow From All
        RewriteEngine On
        RewriteCond %{QUERY_STRING} (manage)
        RewriteRule ^Mobile http://%{HTTP_HOST}/Mobile/web=%1 [NC,L]
    </Directory>
</VirtualHost>

Like http://localhost:8081/Mobile/register should be replaced with http://localhost:8081/Mobile/web/register Please Suggest

Anand Kadhi
  • 1,790
  • 4
  • 27
  • 40

1 Answers1

0

It looks like you want to redirect only when the Query String contains a word "manage":

RewriteCond %{QUERY_STRING} (manage)

If you want to redirect when the Query String doesn't contain a certain word you can use a pattern like this:

RewriteCond %{QUERY_STRING} (!manage)

And the rewrite rule like this one:

 RewriteRule ^Mobile /Mobile/web/register [NC,L,QSA]

QSA may be helpful here:

Appends any query string from the original request URL to any query string created in the rewrite target.

This solution will pass all of the Query String parameters and redirect from http://localhost:8081/Mobile/register?arg1=value1&arg2=value2 to http://localhost:8081/Mobile/web/register?arg1=value1&arg2=value2.

Mateusz Kleinert
  • 1,316
  • 11
  • 20