Error in final bar with mod_rewrite and mod_jk

Asked

Viewed 366 times

3

I have the following structure on my server.

  • Apache HTTPD (port 80)
  • Tomcat (gate 8080)

I used the mod_jk to make the connection between apache and Tomcat and this is working perfectly.

I created a subdomain to point to an application that is in Tomcat. And I made the following Virtualhost configuration.

<VirtualHost *:80>
    ServerName www.cardapio.dreamt.com.br
    ServerAlias cardapio.dreamt.com.br
    JkMount /cardapio/* worker1
    RewriteEngine On
    RewriteRule ^/(.*) /cardapio/$1 [L,PT]
</VirtualHost>

But ,and I ran into two problems:

  1. When accessing cardapio.dreamt.com.br/dreamtech/ (with the bar at the end) the application runs without any problem. And by accessing cardapio.dreamt.com.br/dreamtech (without the end bar) I am redirected to an invalid URL cardapio.dreamt.com.br/cardapio/dreamtech/.
  2. When accessing menu.dreamt.com.br/ my application does not work because it is trying to get the JS and CSS of cardapio.dreamt.com.br/cardapio/xxx.js (for example). And I can’t change because these Imports are done automatically by JSF.

How to solve these problems?

1 answer

1

The following rewrite rule adds a bar to the end specifically in the case of access to the path /dreamtech:

RewriteRule ^(dreamtech)$ $1/ [R]

Try to put it this way:

<VirtualHost *:80>
    ServerName www.cardapio.dreamt.com.br
    ServerAlias cardapio.dreamt.com.br
    JkMount /cardapio/* worker1
    RewriteEngine On
    RewriteRule ^(dreamtech)$ $1/ [R]
    RewriteRule ^/(.*) /cardapio/$1 [L,PT]
</VirtualHost>

Apache’s own guide gives some tips on this bar issue and recommends this type of approach. See here.

Previously, I had made an attempt using the generic rewriting condition to check if the URL related to a file, but that wouldn’t work at all, since you are connecting to a Tomcat.

You can do some tests of the rewrite module here or here.

  • Even with that change, it didn’t work. Without the bar I was redirecting to http://cardapio.dreamt.com.br/cardapio//cardapio//cardapio//cardapio//cardapio//cardapio//cardapio//cardapio//cardapio//cardapio///dreamtech/

  • @gtonioli I reworked the answer. Please do a test again.

  • It didn’t work utluiz. I’ll do some on the sites you indicated.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.