?
Solved

Apache RewriteRule does not work out for wild cards

Posted on 2011-04-29
12
Medium Priority
?
428 Views
Last Modified: 2012-05-11
Hi,

I need to write a rewrite rule in my Apache server Version 2.2.10.

My URL request contains a ? in it which should actually be preceeded by a /, but due to a product bug, the / is missing. So,

The correct URL is something like : http://anything.com/ask/?0.10101
But, now it is passed like http://anything.com/ask?0.10101
due to the bug.

How should I write a rule to insert a / before the ?. I tried out the below with no success :

RewriteEngine on
RewriteRule ^/ask(\?.*)$ http://anything.com/ask/$1 [R,L]

Regards
Harish
0
Comment
Question by:harish_ravi
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 26

Expert Comment

by:arober11
ID: 35496339
Hi

The following should suffice:

RewriteEngine on
RewriteRule ^/ask$ /ask/ [R=301,L]
0
 

Author Comment

by:harish_ravi
ID: 35502887
Hi Arober,

I guess this solution wont work out most possibly because we also have URL's structured as /askxyz/ apart from /ask/. So, in this case, I am not pretty sure how much possibly a solution this can be?

Regards
Harish
0
 
LVL 4

Expert Comment

by:a1j
ID: 35503210
ravi $ matches end of string so askxyz will not match ask$
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 43

Expert Comment

by:ravenpl
ID: 35503259
The ? sign is not part of the url(unless escaped or passed as hex etc.) - that's the query string delimiter. Therefore in Your case

RewriteEngine on
#if theres an query string(possibly optional)
RewriteCond %{QUERY_STRING} .+
#and it matches /ask* without the ending / (remove leading / from match if rule used in .htaccess)
RewriteRule ^/(ask[^/]*)$ /$1/ [R=301,L]
0
 

Author Comment

by:harish_ravi
ID: 35503966
Hi,

Those options did not work out,. Maybe some more briefing of this situation could help you out.

The exact proxypass is configured as below :

ProxyPass /InfoViewApp balancer://xxxx/InfoViewApp  lbmethod=byrequests stickysession=JSESSIONID nofailover=On
ProxyPassReverse      /InfoViewApp      InfoViewApp
ProxyPassReverse      /InfoViewApp      http://localhost:8081/InfoViewApp
ProxyPassReverse      /InfoViewApp      http://localhost:8082/InfoViewApp
ProxyPassReverse      /InfoViewApp      http://localhost:8083/InfoViewApp

ProxyPass /InfoViewAppActions balancer://xxxx/InfoViewAppActions  lbmethod=byrequests stickysession=JSESSIONID nofailover=On
ProxyPassReverse      /InfoViewAppActions      http://localhost:8080/InfoViewAppActions
ProxyPassReverse      /InfoViewAppActions      http://localhost:8081/InfoViewAppActions
ProxyPassReverse      /InfoViewAppActions      http://localhost:8082/InfoViewAppActions
ProxyPassReverse      /InfoViewAppActions      http://localhost:8083/InfoViewAppActions

The URL should be in the form : /InfoViewApp/?0.12222
But, now after a patching of the application, apart from that URL, few requests provide this URL also : /InfoViewApp?0.12222, this is not accepted by Apache. I must now rewrite these URL's back to the old type i.e., insert a / before the ? if it is missing.

Thanks for your timely help!

This situation is too critical for us. Please provide your valuable contribution in solving this !

Regards
Harish
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 35503990
I'm not so familiar with apache proxy, but why will not You try proxying the end-slashed urls?
ProxyPass /InfoViewApp/ balancer://xxxx/InfoViewApp/
ProxyPassReverse      /InfoViewApp/      InfoViewApp/
and so on...
0
 

Author Comment

by:harish_ravi
ID: 35504053
I have now proxied the end slashed URL's but, no use. Still the response from TOMCAT is 302 and Apache throws me out of the page. But, the page redirect is successful if I hit the TOMCAT node directly without using Apache !

Yes, of course that is because our browsers can handle 302 codes easily.But, configuring Apache to handle this situation is the problem.

Regards
Harish
0
 
LVL 4

Expert Comment

by:a1j
ID: 35506643
Harish:  make sure you have

ProxyPreserveHost on
ProxyRequests Off
ProxyVia On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>

in your apache config, it seems like you have at least the first line absent thats why your tomcat complains because Host header changes in mod_proxy.

Also ProxyPassReverse  should be set to /InfoViewApp balancer://xxxx/InfoViewApp


0
 

Author Comment

by:harish_ravi
ID: 35510526
Hi,

Even tried that too without any success :(

I wonder why the following line is'nt working too :

ProxyPassMatch ^InfoViewApp([^A/].*)$ https://domain.net/InfoViewApp/$1

This should check for /InfoViewApp not followed by a 'A' or a ' / ' . So, the Url's in the form /InfoViewApp?0.123124 should be passed as https://domain.net/InfoViewApp/?0.123124.

Is'nt this a type of redirect too?

Regards
Harish
0
 
LVL 4

Expert Comment

by:a1j
ID: 35513993
Its not redirect, its a proxy. It may not work for many reasons...
1. your domain.net cannot be resolved from apache server (should use IP preferably)
2. You have a firewall taht is blocking access to domain.net from apache server...
3. you enabled mod_proxy but forgot to enable mod_proxy_http in your apache config...
0
 

Accepted Solution

by:
harish_ravi earned 0 total points
ID: 35727077
Hi,

the below worked

RewriteRule ^/InfoViewApp$ https://domain/InfoViewApp/ [L,QSA]

Thanks a lot for all your comments.

Regards
Harish
0
 

Author Closing Comment

by:harish_ravi
ID: 35762952
This solution was given by another member in another post. It worked out.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question