Forum Moderators: phranque

Message Too Old, No Replies

apache mod rewrite issue with trailing slash - Need Help

apache mod_rewrite issue with trailing slash with integration to mod_cluste

         

lkrao31

4:37 am on Mar 14, 2016 (gmt 0)

10+ Year Member



Hello All,

We are having jboss web server 3.0.2 (apache2.4) and application server JBOSS EAP 6.2 , I am trying to achieve the below requirement.

a) internal user enters https://example.com/abc-ui , it should redirect calls to application abc with context root (/abc-ui) hosted on an EAP Cluster A

b) internal user enters https://example.com/def-ui, it should redirect calls to application def with context root (/def-ui) hosted on the EAP Cluster A

c) external users enter https://example.com/client/cef , it should redirect calls to application abc with context root (/abc-ui) hosed on EAP Cluster A

d) external users enter https://example.com/client/tal , it should redirect calls to liferay portal application with context root (/lportal) hosted on the EAP Cluster B

I was able to achieve all my above requirement with the below configuration in apache.
**But the issue I am having is if user enters https://example.com/client/cef it is throwing 404 errors , and it works good when user enters https://example.com/client/cef/
I am struggling to add that trailing slash after cef , Can any one please help**

Below is my code snippet in apache http.conf

<VirtualHost *:7200>
RewriteEngine On
RewriteRule ^/client/cef/(.*)$ /aptp-web/$1 [PT,L]
RewriteRule ^/client/tal(.*)$ /portal/$1 [PT,L]
</VirtualHost>

LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
LoadModule cluster_slotmem_module modules/mod_cluster_slotmem.so
LoadModule manager_module modules/mod_manager.so
LoadModule advertise_module modules/mod_advertise.so

MemManagerFile "/weblogs/HTTPServerAptpDevCONINT/cache/mod_cluster"

<IfModule manager_module>
Listen 7080
LogLevel info
RewriteRule ^/abc-ui/(.*)$ balancer://clusterA/abc-ui/$1 [PT,L]
RewriteRule ^/def-ui/(.*)$ balancer://ClusterA/def-ui/$1 [PT,L]
RewriteRule ^/lportal/(.*)$ balancer://ClusterB/$1 [PT,L]
<VirtualHost *:7080>
KeepAliveTimeout 60
MaxKeepAliveRequests 0
EnableMCPMReceive on
ServerAdvertise off
AdvertiseFrequency 5
<Directory />
Order deny,allow
Require all granted
</Directory>
<Location /mod_cluster-manager>
SetHandler mod_cluster-manager
Order deny,allow
Require all granted
</Location>
</VirtualHost>
</IfModule>

Thank you
lkrao

lucy24

5:35 am on Mar 14, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Congratulations! You've managed to ask a question that has not been asked seventeen lakh* times in the history of this forum. This will be fun.

First off: Would it be easier if you used the real names of all your paths and URLs instead of abc and def? It's perfectly permissible, so long as you stick with "example.com", and I think it might make things easier to sort out. It also means there's no risk of typos when you're editing from Real Name to Made-Up Name.

c) external users enter https://example.com/client/cef , it should redirect calls to application abc with context root (/abc-ui) hosed on EAP Cluster A
...
But the issue I am having is if user enters https://example.com/client/cef it is throwing 404 errors , and it works good when user enters https://example.com/client/cef/
I am struggling to add that trailing slash after cef

Do you mean that the intended redirect isn't taking place? Or that your clients get a 404 after the site has redirected them to the intended URL? And it only happens with this one of your four scenarios?

When you say "redirect" do you mean "rewrite"? In a situation like this, it's absolutely essential to get the terminology right, so we're not talking at cross purposes. Rewrite, as opposed to redirect, means that users enter
various-stuff
and then the site serves content from
various-other-stuff
while the user's address bar doesn't change. In which case, what's the [PT] even doing there? Wouldn't it be simpler to use the real filepaths if the user is none the wiser?

Is the difference between "external users" and "internal users" important to the rule? Or do you just mean that they go through different types of validation?

Let's try it again with the real names.

But first, just to make sure the RewriteEngine is working, try some nonsense rule like
RewriteRule foo http://example.com/bar.html [R=301,L]
and verify that the redirect takes place. It's not likely to be a mod_rewrite problem-- but it's the easiest thing to fix, so do double-check.


* Possibly seventeen crore. I lost count.

whitespace

8:47 am on Mar 14, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month




RewriteRule ^/client/cef/(.*)$ /aptp-web/$1 [PT,L]
RewriteRule ^/client/tal(.*)$ /portal/$1 [PT,L]


Why do you have a trailing slash on one and not the other?

lucy24

3:50 pm on Mar 14, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Urk, missed that. Or, more precisely: Why do you require (but not capture) a slash on one, and not require (but do capture if present) a slash on the other? So add that to the list of questions: What's the possible content after /cef or /tal or similar?