You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Fedor Makarov <ar...@mail.ru.INVALID> on 2022/12/27 06:25:52 UTC

Problems with requests without trailing slash Tomcat 9.0.65

 
Tomcat 9.0.65
Hello I have some problems with redirects by requests without trailing slashes.
 
When I try to get to the page for example: "about/page" tomcat understands that it is necessary to add a slash and adds it, however, he also adds the name of the root folder to this, that is, the url "lundase/about/page/" turns out, and any requests to our server via apache are proxied with the addition of "lundase", so it turns out that we are accessing the application on request "lundase/lundase/about/page/" which results in a 404 status.
 
I googled it and found two properties:  
context.setMapperContextRootRedirectEnabled(false)
context.setMapperDirectoryRedirectEnabled(false)
And tryed to play with them, however, it's not resolve my problem please can you help me with it?
 
<?xml version="1.0" encoding="UTF-8"?>
<web-app >
<display-name>Main lundagrossisten site</display-name>
<description>lundagrossisten.se web application</description>
<session-config>
<session-timeout>1</session-timeout>
<cookie-config>
<max-age>0</max-age>
</cookie-config>
</session-config>

<servlet>
<servlet-name>client-error-logging-servlet</servlet-name>
<servlet-class>com.gridnine.platform.server.lundase.web.servlet.ClientErrorLoggingServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>client-error-logging-servlet</servlet-name>
<url-pattern>/client-error/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>warehouses-servlet</servlet-name>
<servlet-class>com.gridnine.platform.server.lundase.web.servlet.WarehousesServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>warehouses-servlet</servlet-name>
<url-pattern>/warehouses/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>propsforrent-servlet</servlet-name>
<servlet-class>com.gridnine.platform.server.lundase.web.servlet.PropertiesForRentServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>propsforrent-servlet</servlet-name>
<url-pattern>/properties-for-rent/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>calendar-events-servlet</servlet-name>
<servlet-class>com.gridnine.platform.server.lundase.web.servlet.CalendarEventsServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>calendar-events-servlet</servlet-name>
<url-pattern>/about/events/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>update-catalogue-servlet</servlet-name>
<servlet-class>com.gridnine.platform.server.lundase.web.servlet.UpdateCatalogueServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>update-catalogue-servlet</servlet-name>
<url-pattern>/ping/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>catalogue-servlet</servlet-name>
<servlet-class>com.gridnine.platform.server.lundase.web.servlet.CatalogueServlet
</servlet-class>
<init-param>
<param-name>catalogue-type</param-name>
<param-value>MAIN</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>catalogue-servlet</servlet-name>
<url-pattern>/catalogue/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>binary-data-servlet</servlet-name>
<servlet-class>com.gridnine.platform.server.lundase.web.servlet.BinaryDataServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>binary-data-servlet</servlet-name>
<url-pattern>/binary/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>content-servlet</servlet-name>
<servlet-class>com.gridnine.platform.server.lundase.web.servlet.ContentServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>content-servlet</servlet-name>
<url-pattern>/content/*</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>cabinet-servlet</servlet-name>
<servlet-class>com.gridnine.platform.server.lundase.web.servlet.CabinetServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cabinet-servlet</servlet-name>
<url-pattern>/lundaprogrammet/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>/source/assets/css/aggregate.css</url-pattern>
</servlet-mapping>

<filter>
<filter-name>auth-filter</filter-name>
<filter-class>com.gridnine.platform.server.lundase.web.servlet.AuthFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>auth-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<error-page>
<location>/error.html</location>
</error-page>

<request-character-encoding>UTF-8</request-character-encoding>
</web-app>
 
The code that doing this redirects:
org.apache.catalina.mapper.Mapper.internalMapWrapper(ContextVersion contextVersion,
                                          CharChunk path,
                                          MappingData mappingData)
---
Fedor Makarov

Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Mark Thomas <ma...@apache.org>.
On 12/01/2023 10:50, Simon Matter wrote:
>> On 12/01/2023 05:08, Fedor Makarov wrote:
>>>
>>> lundase and vvsguiden webapps used on different domains
>>
>> My recommendation would be to configure Tomcat for virtual hosting as
>> well. [1]
>>
>> For example, configure the following hosts in the local hosts file:
>>
>> lundase-local
>> vvsguiden-local
>>
>> Then the httpd redirects become:
>>
>> RewriteRule ^(.*)$ http://lundase-local:9090/$1 [P]
>>
>> and
>>
>> RewriteRule ^(.*)$ http://vvsguiden-local:9090/$1 [P]
>                                         ^^^^^^^^^^^^^^^
> That's a typo and meant to be 9091?

No. This is virtual hosting.

Mark

> 
>>
>> respectively.
>>
>> And in Tomcat you have:
>>
>> <Engine name="Catalina" defaultHost="lundase-local">
>>       <Host name="lundase-local"   appBase="webapps-lundase"/>
>>       <Host name="vvsguiden-local" appBase="webapps-vvsguiden"/>
>> </Engine>
>>
>> With appropriate ROOT.war files (and any additional web applications)
>> deployed in the appropriate webapps-... directory.
>>
>> If you don't want to go the virtual hosting route, you could have
>> multiple Tomcat instances on different ports or multiple <Service>
>> elements in one instance e.g.
>>
>> <Server .../>
>>     ...
>>     <Service name="lundase">
>>       <Connector port="9090" .../>
>>       <Engine name="lundase" defaultHost="localhost">
>>         ...
>>       </Engine>
>>     </Service>
>>     <Service name="vvsguiden">
>>       <Connector port="9091" .../>
>>       <Engine name="vvsguiden" defaultHost="localhost">
>>         ...
>>       </Engine>
>>     </Service>
>> </Server>
>>
>> Although I do think the virtual hosting approach is the simplest - and
>> it maps neatly to the httpd configuration.
>>
>> Mark
>>
>> [1] https://tomcat.apache.org/tomcat-9.0-doc/virtual-hosting-howto.html
>>
>>
>>>
>>> <VirtualHost *:80>
>>> <------>ServerName new.vvsguiden-dev.gridnine.com
>>> <------>ServerAlias localhost
>>> <------>ServerAdmin webmaster@localhost
>>> <------>DocumentRoot /var/www/html
>>>
>>> <------>RewriteEngine on
>>>
>>> <------>ProxyPreserveHost on
>>>
>>>           <Directory "/site-binary-data/fb">
>>>               Order allow,deny
>>>               Allow from all
>>>               Require all granted
>>>           </Directory>
>>>
>>>           # static content
>>>           RewriteRule ^/fb/(.*)$ /site-binary-data/fb/$1 [L]
>>>
>>> <------>RewriteRule     ^/vvsguidenapi/(.*)$
>>>         http://localhost:9090/vvsguidenapi/$1 [NC,P,L]
>>> <------>RewriteRule     ^(.*)$
>>> http://localhost:9090/vvsguiden/$1 [NC,P,L]
>>> <------>
>>>
>>> <VirtualHost *:443>
>>> <------>ServerName m.new.lundagrossisten-dev.gridnine.com
>>> <------>ServerAdmin webmaster@localhost
>>>
>>> <------><LocationMatch "^/lundaprogrammet/.*">
>>>> Вторник, 10 января 2023, 11:41 +03:00 от Mark Thomas
>>>> <ma...@apache.org>:
>>>>
>>>> On 10/01/2023 04:37, Fedor Makarov wrote:
>>>>>
>>>>> Also I tried to write a filter to manually redirect, but tomcat
>>>>> intercepts the request before it gets into the filter. Can I disable
>>>>> this behavior for tomcat and do it manually?
>>>>
>>>> That isn't the way to solve this problem. The problem is in the reverse
>>>> proxy configuration and that is where you need to fix it.
>>>>
>>>> You previously provided the following set of rules:
>>>>
>>>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>>>
>>>> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1
>>>> [NC,P,L]
>>>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>>>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>>>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>>>
>>>> I'll note that the RewriteCond appears to be unnecessary.
>>>>
>>>> I'll further note that the NC flag appears to be unnecessary. As is the
>>>> L flag (P implies L).
>>>>
>>>> We can help you fix these rules but when we tried you mentioned
>>>> "vvsguiden" but that does not appear in the rewrite rules.
>>>>
>>>>
>>>> mod_rewrite isn't necessarily the best way to configure a reverse proxy
>>>> but if that is what you are familiar with, we can work with it. What we
>>>> do need, regardless of how the reverse proxy is configured, is a
>>>> complete list of the mappings you want to implement.
>>>>
>>>> To re-iterate Chris's earlier point, trying to change the context path
>>>> for an application in a reverse proxy is asking for trouble. It is far
>>>> better to reconfigure the contexts in Tomcat so the reverse proxy
>>>> doesn't need to change the URI path.
>>>>
>>>> Based on the paths above, you need to redeploy lundase.war as ROOT.war
>>>> and then the rewrite rules become:
>>>>
>>>> RewriteRule ^(.*)$ http://localhost:9090/$1 [P]
>>>>
>>>> We need more details for "vvsguiden" to figure out why the above won't
>>>> work.
>>>>
>>>> Mark
>>>>
>>>>
>>>>>
>>>>>
>>>>>> Понедельник, 9 января 2023, 11:43 +03:00 от Fedor Makarov <
>>>>>> aryiia@mail.ru.invalid >:
>>>>>>
>>>>>>
>>>>>>
>>>>>> We have to webapps lundase and vvsguiden therefore, the options you
>>>>>> have suggested do not look applicable on debug I saw that RequestURI
>>>>>> in request looks like lundase/lundase/...
>>>>>>
>>>>>>> Вторник, 27 декабря 2022, 22:06 +03:00 от Christopher Schultz <
>>>>>>> chris@christopherschultz.net >:
>>>>>>>
>>>>>>> Fedor,
>>>>>>>
>>>>>>> On 12/27/22 05:55, Fedor Makarov wrote:
>>>>>>>>
>>>>>>>> proxy for local environment we use the js conf:
>>>>>>>> proxy: {
>>>>>>>>       '/api/': {
>>>>>>>>         target: 'http://localhost:8080/',
>>>>>>>>         changeOrigin: false,
>>>>>>>>       },
>>>>>>>>       '/': {
>>>>>>>>         target: 'http://localhost:8080/lundase',
>>>>>>>>         changeOrigin: false
>>>>>>>>       }
>>>>>>>>     },
>>>>>>>>
>>>>>>>> for normal lunch we use apache2.conf:
>>>>>>>>
>>>>>>>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>>>>>>>
>>>>>>>> RewriteRule ^/rpc/invoker/(.*)$
>>>>>>>> http://localhost:9090/rpc/invoker/$1 [NC,P,L]
>>>>>>>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>>>>>>>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>>>>>>>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>>>>>>
>>>>>>> What you are doing is trying to remove the context-path of the
>>>>>>> application through URL re-writing which will probably cause endless
>>>>>>> problems during the life of your application.
>>>>>>>
>>>>>>> I have two possible suggestions for you:
>>>>>>>
>>>>>>> 1. Re-name your application from lundase to ROOT (to deploy it to /
>>>>>>> instead of /lundase).
>>>>>>>
>>>>>>> or
>>>>>>>
>>>>>>> 2. Don't try to remove the /lundase URL prefix as part of your URL
>>>>>>> rewriting.
>>>>>>>
>>>>>>> If you don't choose one or the other of these options, you will find
>>>>>>> that you have many years of debugging and trying to fix up every
>>>>>>> little
>>>>>>> weird thing that happens with cookies, redirects, and in-page links.
>>>>>>>
>>>>>>> -chris
>>>>>>>
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>>>>>>> For additional commands, e-mail:  users-help@tomcat.apache.org
>>>>>>
>>>>>> ---
>>>>>> Fedor Makarov
>>>>>>
>>>>>
>>>>>
>>>>> ---
>>>>> Fedor Makarov
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail:  users-help@tomcat.apache.org
>>>
>>>
>>> ---
>>> Fedor Makarov
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Simon Matter <si...@invoca.ch>.
> On 12/01/2023 05:08, Fedor Makarov wrote:
>>
>> lundase and vvsguiden webapps used on different domains
>
> My recommendation would be to configure Tomcat for virtual hosting as
> well. [1]
>
> For example, configure the following hosts in the local hosts file:
>
> lundase-local
> vvsguiden-local
>
> Then the httpd redirects become:
>
> RewriteRule ^(.*)$ http://lundase-local:9090/$1 [P]
>
> and
>
> RewriteRule ^(.*)$ http://vvsguiden-local:9090/$1 [P]
                                       ^^^^^^^^^^^^^^^
That's a typo and meant to be 9091?

>
> respectively.
>
> And in Tomcat you have:
>
> <Engine name="Catalina" defaultHost="lundase-local">
>      <Host name="lundase-local"   appBase="webapps-lundase"/>
>      <Host name="vvsguiden-local" appBase="webapps-vvsguiden"/>
> </Engine>
>
> With appropriate ROOT.war files (and any additional web applications)
> deployed in the appropriate webapps-... directory.
>
> If you don't want to go the virtual hosting route, you could have
> multiple Tomcat instances on different ports or multiple <Service>
> elements in one instance e.g.
>
> <Server .../>
>    ...
>    <Service name="lundase">
>      <Connector port="9090" .../>
>      <Engine name="lundase" defaultHost="localhost">
>        ...
>      </Engine>
>    </Service>
>    <Service name="vvsguiden">
>      <Connector port="9091" .../>
>      <Engine name="vvsguiden" defaultHost="localhost">
>        ...
>      </Engine>
>    </Service>
> </Server>
>
> Although I do think the virtual hosting approach is the simplest - and
> it maps neatly to the httpd configuration.
>
> Mark
>
> [1] https://tomcat.apache.org/tomcat-9.0-doc/virtual-hosting-howto.html
>
>
>>
>> <VirtualHost *:80>
>> <------>ServerName new.vvsguiden-dev.gridnine.com
>> <------>ServerAlias localhost
>> <------>ServerAdmin webmaster@localhost
>> <------>DocumentRoot /var/www/html
>>
>> <------>RewriteEngine on
>>
>> <------>ProxyPreserveHost on
>>
>>          <Directory "/site-binary-data/fb">
>>              Order allow,deny
>>              Allow from all
>>              Require all granted
>>          </Directory>
>>
>>          # static content
>>          RewriteRule ^/fb/(.*)$ /site-binary-data/fb/$1 [L]
>>
>> <------>RewriteRule     ^/vvsguidenapi/(.*)$                            
>>        http://localhost:9090/vvsguidenapi/$1 [NC,P,L]
>> <------>RewriteRule     ^(.*)$                                        
>> http://localhost:9090/vvsguiden/$1 [NC,P,L]
>> <------>
>>
>> <VirtualHost *:443>
>> <------>ServerName m.new.lundagrossisten-dev.gridnine.com
>> <------>ServerAdmin webmaster@localhost
>>
>> <------><LocationMatch "^/lundaprogrammet/.*">
>>> Вторник, 10 января 2023, 11:41 +03:00 от Mark Thomas
>>> <ma...@apache.org>:
>>>
>>> On 10/01/2023 04:37, Fedor Makarov wrote:
>>>>
>>>> Also I tried to write a filter to manually redirect, but tomcat
>>>> intercepts the request before it gets into the filter. Can I disable
>>>> this behavior for tomcat and do it manually?
>>>
>>> That isn't the way to solve this problem. The problem is in the reverse
>>> proxy configuration and that is where you need to fix it.
>>>
>>> You previously provided the following set of rules:
>>>
>>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>>
>>> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1
>>> [NC,P,L]
>>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>>
>>> I'll note that the RewriteCond appears to be unnecessary.
>>>
>>> I'll further note that the NC flag appears to be unnecessary. As is the
>>> L flag (P implies L).
>>>
>>> We can help you fix these rules but when we tried you mentioned
>>> "vvsguiden" but that does not appear in the rewrite rules.
>>>
>>>
>>> mod_rewrite isn't necessarily the best way to configure a reverse proxy
>>> but if that is what you are familiar with, we can work with it. What we
>>> do need, regardless of how the reverse proxy is configured, is a
>>> complete list of the mappings you want to implement.
>>>
>>> To re-iterate Chris's earlier point, trying to change the context path
>>> for an application in a reverse proxy is asking for trouble. It is far
>>> better to reconfigure the contexts in Tomcat so the reverse proxy
>>> doesn't need to change the URI path.
>>>
>>> Based on the paths above, you need to redeploy lundase.war as ROOT.war
>>> and then the rewrite rules become:
>>>
>>> RewriteRule ^(.*)$ http://localhost:9090/$1 [P]
>>>
>>> We need more details for "vvsguiden" to figure out why the above won't
>>> work.
>>>
>>> Mark
>>>
>>>
>>>>
>>>>
>>>>> Понедельник, 9 января 2023, 11:43 +03:00 от Fedor Makarov <
>>>>> aryiia@mail.ru.invalid >:
>>>>>
>>>>>
>>>>>
>>>>> We have to webapps lundase and vvsguiden therefore, the options you
>>>>> have suggested do not look applicable on debug I saw that RequestURI
>>>>> in request looks like lundase/lundase/...
>>>>>
>>>>>> Вторник, 27 декабря 2022, 22:06 +03:00 от Christopher Schultz <
>>>>>> chris@christopherschultz.net >:
>>>>>>
>>>>>> Fedor,
>>>>>>
>>>>>> On 12/27/22 05:55, Fedor Makarov wrote:
>>>>>>>
>>>>>>> proxy for local environment we use the js conf:
>>>>>>> proxy: {
>>>>>>>      '/api/': {
>>>>>>>        target: 'http://localhost:8080/',
>>>>>>>        changeOrigin: false,
>>>>>>>      },
>>>>>>>      '/': {
>>>>>>>        target: 'http://localhost:8080/lundase',
>>>>>>>        changeOrigin: false
>>>>>>>      }
>>>>>>>    },
>>>>>>>
>>>>>>> for normal lunch we use apache2.conf:
>>>>>>>
>>>>>>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>>>>>>
>>>>>>> RewriteRule ^/rpc/invoker/(.*)$
>>>>>>> http://localhost:9090/rpc/invoker/$1 [NC,P,L]
>>>>>>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>>>>>>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>>>>>>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>>>>>
>>>>>> What you are doing is trying to remove the context-path of the
>>>>>> application through URL re-writing which will probably cause endless
>>>>>> problems during the life of your application.
>>>>>>
>>>>>> I have two possible suggestions for you:
>>>>>>
>>>>>> 1. Re-name your application from lundase to ROOT (to deploy it to /
>>>>>> instead of /lundase).
>>>>>>
>>>>>> or
>>>>>>
>>>>>> 2. Don't try to remove the /lundase URL prefix as part of your URL
>>>>>> rewriting.
>>>>>>
>>>>>> If you don't choose one or the other of these options, you will find
>>>>>> that you have many years of debugging and trying to fix up every
>>>>>> little
>>>>>> weird thing that happens with cookies, redirects, and in-page links.
>>>>>>
>>>>>> -chris
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>>>>>> For additional commands, e-mail:  users-help@tomcat.apache.org
>>>>>
>>>>> ---
>>>>> Fedor Makarov
>>>>>
>>>>
>>>>
>>>> ---
>>>> Fedor Makarov
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail:  users-help@tomcat.apache.org
>>
>>
>> ---
>> Fedor Makarov
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Mark Thomas <ma...@apache.org>.
On 12/01/2023 05:08, Fedor Makarov wrote:
> 
> lundase and vvsguiden webapps used on different domains

My recommendation would be to configure Tomcat for virtual hosting as 
well. [1]

For example, configure the following hosts in the local hosts file:

lundase-local
vvsguiden-local

Then the httpd redirects become:

RewriteRule ^(.*)$ http://lundase-local:9090/$1 [P]

and

RewriteRule ^(.*)$ http://vvsguiden-local:9090/$1 [P]

respectively.

And in Tomcat you have:

<Engine name="Catalina" defaultHost="lundase-local">
     <Host name="lundase-local"   appBase="webapps-lundase"/>
     <Host name="vvsguiden-local" appBase="webapps-vvsguiden"/>
</Engine>

With appropriate ROOT.war files (and any additional web applications) 
deployed in the appropriate webapps-... directory.

If you don't want to go the virtual hosting route, you could have 
multiple Tomcat instances on different ports or multiple <Service> 
elements in one instance e.g.

<Server .../>
   ...
   <Service name="lundase">
     <Connector port="9090" .../>
     <Engine name="lundase" defaultHost="localhost">
       ...
     </Engine>
   </Service>
   <Service name="vvsguiden">
     <Connector port="9091" .../>
     <Engine name="vvsguiden" defaultHost="localhost">
       ...
     </Engine>
   </Service>
</Server>

Although I do think the virtual hosting approach is the simplest - and 
it maps neatly to the httpd configuration.

Mark

[1] https://tomcat.apache.org/tomcat-9.0-doc/virtual-hosting-howto.html


>   
> <VirtualHost *:80>
> <------>ServerName new.vvsguiden-dev.gridnine.com
> <------>ServerAlias localhost
> <------>ServerAdmin webmaster@localhost
> <------>DocumentRoot /var/www/html
>   
> <------>RewriteEngine on
>   
> <------>ProxyPreserveHost on
>   
>          <Directory "/site-binary-data/fb">
>              Order allow,deny
>              Allow from all
>              Require all granted
>          </Directory>
>   
>          # static content
>          RewriteRule ^/fb/(.*)$ /site-binary-data/fb/$1 [L]
>   
> <------>RewriteRule     ^/vvsguidenapi/(.*)$                                    http://localhost:9090/vvsguidenapi/$1 [NC,P,L]
> <------>RewriteRule     ^(.*)$                                         http://localhost:9090/vvsguiden/$1 [NC,P,L]
> <------>
>   
> <VirtualHost *:443>
> <------>ServerName m.new.lundagrossisten-dev.gridnine.com
> <------>ServerAdmin webmaster@localhost
>   
> <------><LocationMatch "^/lundaprogrammet/.*">
>> Вторник, 10 января 2023, 11:41 +03:00 от Mark Thomas <ma...@apache.org>:
>>   
>> On 10/01/2023 04:37, Fedor Makarov wrote:
>>>
>>> Also I tried to write a filter to manually redirect, but tomcat intercepts the request before it gets into the filter. Can I disable this behavior for tomcat and do it manually?
>>
>> That isn't the way to solve this problem. The problem is in the reverse
>> proxy configuration and that is where you need to fix it.
>>
>> You previously provided the following set of rules:
>>
>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>
>> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1
>> [NC,P,L]
>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>
>> I'll note that the RewriteCond appears to be unnecessary.
>>
>> I'll further note that the NC flag appears to be unnecessary. As is the
>> L flag (P implies L).
>>
>> We can help you fix these rules but when we tried you mentioned
>> "vvsguiden" but that does not appear in the rewrite rules.
>>
>>
>> mod_rewrite isn't necessarily the best way to configure a reverse proxy
>> but if that is what you are familiar with, we can work with it. What we
>> do need, regardless of how the reverse proxy is configured, is a
>> complete list of the mappings you want to implement.
>>
>> To re-iterate Chris's earlier point, trying to change the context path
>> for an application in a reverse proxy is asking for trouble. It is far
>> better to reconfigure the contexts in Tomcat so the reverse proxy
>> doesn't need to change the URI path.
>>
>> Based on the paths above, you need to redeploy lundase.war as ROOT.war
>> and then the rewrite rules become:
>>
>> RewriteRule ^(.*)$ http://localhost:9090/$1 [P]
>>
>> We need more details for "vvsguiden" to figure out why the above won't work.
>>
>> Mark
>>
>>
>>>
>>>
>>>> Понедельник, 9 января 2023, 11:43 +03:00 от Fedor Makarov < aryiia@mail.ru.invalid >:
>>>>
>>>>
>>>>
>>>> We have to webapps lundase and vvsguiden therefore, the options you have suggested do not look applicable on debug I saw that RequestURI in request looks like lundase/lundase/...
>>>>
>>>>> Вторник, 27 декабря 2022, 22:06 +03:00 от Christopher Schultz <  chris@christopherschultz.net >:
>>>>>
>>>>> Fedor,
>>>>>
>>>>> On 12/27/22 05:55, Fedor Makarov wrote:
>>>>>>
>>>>>> proxy for local environment we use the js conf:
>>>>>> proxy: {
>>>>>>      '/api/': {
>>>>>>        target: 'http://localhost:8080/',
>>>>>>        changeOrigin: false,
>>>>>>      },
>>>>>>      '/': {
>>>>>>        target: 'http://localhost:8080/lundase',
>>>>>>        changeOrigin: false
>>>>>>      }
>>>>>>    },
>>>>>>
>>>>>> for normal lunch we use apache2.conf:
>>>>>>
>>>>>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>>>>>
>>>>>> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 [NC,P,L]
>>>>>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>>>>>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>>>>>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>>>>
>>>>> What you are doing is trying to remove the context-path of the
>>>>> application through URL re-writing which will probably cause endless
>>>>> problems during the life of your application.
>>>>>
>>>>> I have two possible suggestions for you:
>>>>>
>>>>> 1. Re-name your application from lundase to ROOT (to deploy it to /
>>>>> instead of /lundase).
>>>>>
>>>>> or
>>>>>
>>>>> 2. Don't try to remove the /lundase URL prefix as part of your URL
>>>>> rewriting.
>>>>>
>>>>> If you don't choose one or the other of these options, you will find
>>>>> that you have many years of debugging and trying to fix up every little
>>>>> weird thing that happens with cookies, redirects, and in-page links.
>>>>>
>>>>> -chris
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>>>>> For additional commands, e-mail:  users-help@tomcat.apache.org
>>>>
>>>> ---
>>>> Fedor Makarov
>>>>
>>>
>>>
>>> ---
>>> Fedor Makarov
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail:  users-help@tomcat.apache.org
>   
>   
> ---
> Fedor Makarov
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Fedor Makarov <ar...@mail.ru.INVALID>.
lundase and vvsguiden webapps used on different domains
 
<VirtualHost *:80>
<------>ServerName new.vvsguiden-dev.gridnine.com
<------>ServerAlias localhost
<------>ServerAdmin webmaster@localhost
<------>DocumentRoot /var/www/html
 
<------>RewriteEngine on
 
<------>ProxyPreserveHost on
 
        <Directory "/site-binary-data/fb">
            Order allow,deny
            Allow from all
            Require all granted
        </Directory>
 
        # static content
        RewriteRule ^/fb/(.*)$ /site-binary-data/fb/$1 [L]
 
<------>RewriteRule     ^/vvsguidenapi/(.*)$                                    http://localhost:9090/vvsguidenapi/$1 [NC,P,L]
<------>RewriteRule     ^(.*)$                                         http://localhost:9090/vvsguiden/$1 [NC,P,L]
<------>
 
<VirtualHost *:443>
<------>ServerName m.new.lundagrossisten-dev.gridnine.com
<------>ServerAdmin webmaster@localhost
 
<------><LocationMatch "^/lundaprogrammet/.*"> 
>Вторник, 10 января 2023, 11:41 +03:00 от Mark Thomas <ma...@apache.org>:
> 
>On 10/01/2023 04:37, Fedor Makarov wrote:
>>
>> Also I tried to write a filter to manually redirect, but tomcat intercepts the request before it gets into the filter. Can I disable this behavior for tomcat and do it manually?
>
>That isn't the way to solve this problem. The problem is in the reverse
>proxy configuration and that is where you need to fix it.
>
>You previously provided the following set of rules:
>
>RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>
>RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1
>[NC,P,L]
>RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>
>I'll note that the RewriteCond appears to be unnecessary.
>
>I'll further note that the NC flag appears to be unnecessary. As is the
>L flag (P implies L).
>
>We can help you fix these rules but when we tried you mentioned
>"vvsguiden" but that does not appear in the rewrite rules.
>
>
>mod_rewrite isn't necessarily the best way to configure a reverse proxy
>but if that is what you are familiar with, we can work with it. What we
>do need, regardless of how the reverse proxy is configured, is a
>complete list of the mappings you want to implement.
>
>To re-iterate Chris's earlier point, trying to change the context path
>for an application in a reverse proxy is asking for trouble. It is far
>better to reconfigure the contexts in Tomcat so the reverse proxy
>doesn't need to change the URI path.
>
>Based on the paths above, you need to redeploy lundase.war as ROOT.war
>and then the rewrite rules become:
>
>RewriteRule ^(.*)$ http://localhost:9090/$1 [P]
>
>We need more details for "vvsguiden" to figure out why the above won't work.
>
>Mark
>
>
>>
>>
>>> Понедельник, 9 января 2023, 11:43 +03:00 от Fedor Makarov < aryiia@mail.ru.invalid >:
>>>
>>>
>>>
>>> We have to webapps lundase and vvsguiden therefore, the options you have suggested do not look applicable on debug I saw that RequestURI in request looks like lundase/lundase/...
>>>
>>>> Вторник, 27 декабря 2022, 22:06 +03:00 от Christopher Schultz <  chris@christopherschultz.net >:
>>>>
>>>> Fedor,
>>>>
>>>> On 12/27/22 05:55, Fedor Makarov wrote:
>>>>>
>>>>> proxy for local environment we use the js conf:
>>>>> proxy: {
>>>>>     '/api/': {
>>>>>       target: 'http://localhost:8080/',
>>>>>       changeOrigin: false,
>>>>>     },
>>>>>     '/': {
>>>>>       target: 'http://localhost:8080/lundase',
>>>>>       changeOrigin: false
>>>>>     }
>>>>>   },
>>>>>
>>>>> for normal lunch we use apache2.conf:
>>>>>
>>>>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>>>>
>>>>> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 [NC,P,L]
>>>>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>>>>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>>>>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>>>
>>>> What you are doing is trying to remove the context-path of the
>>>> application through URL re-writing which will probably cause endless
>>>> problems during the life of your application.
>>>>
>>>> I have two possible suggestions for you:
>>>>
>>>> 1. Re-name your application from lundase to ROOT (to deploy it to /
>>>> instead of /lundase).
>>>>
>>>> or
>>>>
>>>> 2. Don't try to remove the /lundase URL prefix as part of your URL
>>>> rewriting.
>>>>
>>>> If you don't choose one or the other of these options, you will find
>>>> that you have many years of debugging and trying to fix up every little
>>>> weird thing that happens with cookies, redirects, and in-page links.
>>>>
>>>> -chris
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail:  users-help@tomcat.apache.org
>>>
>>> ---
>>> Fedor Makarov
>>>
>>
>>
>> ---
>> Fedor Makarov
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail:  users-help@tomcat.apache.org 
 
 
---
Fedor Makarov
 

Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Mark Thomas <ma...@apache.org>.
On 10/01/2023 04:37, Fedor Makarov wrote:
> 
> Also I tried to write a filter to manually redirect, but tomcat intercepts the request before it gets into the filter. Can I disable this behavior for tomcat and do it manually?

That isn't the way to solve this problem. The problem is in the reverse 
proxy configuration and that is where you need to fix it.

You previously provided the following set of rules:

RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)

RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 
[NC,P,L]
RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]

I'll note that the RewriteCond appears to be unnecessary.

I'll further note that the NC flag appears to be unnecessary. As is the 
L flag (P implies L).

We can help you fix these rules but when we tried you mentioned 
"vvsguiden" but that does not appear in the rewrite rules.


mod_rewrite isn't necessarily the best way to configure a reverse proxy 
but if that is what you are familiar with, we can work with it. What we 
do need, regardless of how the reverse proxy is configured, is a 
complete list of the mappings you want to implement.

To re-iterate Chris's earlier point, trying to change the context path 
for an application in a reverse proxy is asking for trouble. It is far 
better to reconfigure the contexts in Tomcat so the reverse proxy 
doesn't need to change the URI path.

Based on the paths above, you need to redeploy lundase.war as ROOT.war 
and then the rewrite rules become:

RewriteRule ^(.*)$ http://localhost:9090/$1 [P]

We need more details for "vvsguiden" to figure out why the above won't work.

Mark


> 
>    
>> Понедельник, 9 января 2023, 11:43 +03:00 от Fedor Makarov <ar...@mail.ru.invalid>:
>>   
>>
>>
>> We have to webapps lundase and vvsguiden therefore, the options you have suggested do not look applicable on debug I saw that RequestURI in request looks like lundase/lundase/...
>>   
>>> Вторник, 27 декабря 2022, 22:06 +03:00 от Christopher Schultz < chris@christopherschultz.net >:
>>>   
>>> Fedor,
>>>
>>> On 12/27/22 05:55, Fedor Makarov wrote:
>>>>
>>>> proxy for local environment we use the js conf:
>>>> proxy: {
>>>>      '/api/': {
>>>>        target: 'http://localhost:8080/',
>>>>        changeOrigin: false,
>>>>      },
>>>>      '/': {
>>>>        target: 'http://localhost:8080/lundase',
>>>>        changeOrigin: false
>>>>      }
>>>>    },
>>>>
>>>> for normal lunch we use apache2.conf:
>>>>
>>>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>>>
>>>> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 [NC,P,L]
>>>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>>>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>>>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>>
>>> What you are doing is trying to remove the context-path of the
>>> application through URL re-writing which will probably cause endless
>>> problems during the life of your application.
>>>
>>> I have two possible suggestions for you:
>>>
>>> 1. Re-name your application from lundase to ROOT (to deploy it to /
>>> instead of /lundase).
>>>
>>> or
>>>
>>> 2. Don't try to remove the /lundase URL prefix as part of your URL
>>> rewriting.
>>>
>>> If you don't choose one or the other of these options, you will find
>>> that you have many years of debugging and trying to fix up every little
>>> weird thing that happens with cookies, redirects, and in-page links.
>>>
>>> -chris
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail:  users-help@tomcat.apache.org
>>   
>> ---
>> Fedor Makarov
>>    
>   
>   
> ---
> Fedor Makarov
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Fedor Makarov <ar...@mail.ru.INVALID>.
Also I tried to write a filter to manually redirect, but tomcat intercepts the request before it gets into the filter. Can I disable this behavior for tomcat and do it manually?

  
>Понедельник, 9 января 2023, 11:43 +03:00 от Fedor Makarov <ar...@mail.ru.invalid>:
> 
>
>
>We have to webapps lundase and vvsguiden therefore, the options you have suggested do not look applicable on debug I saw that RequestURI in request looks like lundase/lundase/...
> 
>>Вторник, 27 декабря 2022, 22:06 +03:00 от Christopher Schultz < chris@christopherschultz.net >:
>> 
>>Fedor,
>>
>>On 12/27/22 05:55, Fedor Makarov wrote:
>>>
>>> proxy for local environment we use the js conf:
>>> proxy: {
>>>     '/api/': {
>>>       target: 'http://localhost:8080/',
>>>       changeOrigin: false,
>>>     },
>>>     '/': {
>>>       target: 'http://localhost:8080/lundase',
>>>       changeOrigin: false
>>>     }
>>>   },
>>>
>>> for normal lunch we use apache2.conf:
>>>
>>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>>
>>> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 [NC,P,L]
>>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>
>>What you are doing is trying to remove the context-path of the
>>application through URL re-writing which will probably cause endless
>>problems during the life of your application.
>>
>>I have two possible suggestions for you:
>>
>>1. Re-name your application from lundase to ROOT (to deploy it to /
>>instead of /lundase).
>>
>>or
>>
>>2. Don't try to remove the /lundase URL prefix as part of your URL
>>rewriting.
>>
>>If you don't choose one or the other of these options, you will find
>>that you have many years of debugging and trying to fix up every little
>>weird thing that happens with cookies, redirects, and in-page links.
>>
>>-chris
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail:  users-help@tomcat.apache.org  
> 
>---
>Fedor Makarov
>  
 
 
---
Fedor Makarov
 

Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Fedor,

On 1/9/23 03:43, Fedor Makarov wrote:
> We have to webapps lundase and vvsguiden therefore, the options you 
> have suggested do not look applicable
Why not?

> on debug I saw that RequestURI in request looks like
> lundase/lundase/...
Probably because of this:

 >>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]

You are taking /lundase and turning it into /lundase/lundase

I think you should do this:

RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 
[NC,P,L]
RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
RewriteRule ^/lundase/(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
RewriteRule ^/vvsguiden/(.*)$ http://localhost:9090/vvsguiden/$1 [NC,P,L]

You can always rewrite /(not api|mapi|lundase|vvsguiden) to /lundase/$1 
-- or, better yet, use a "permanent redirect".

But you need to remove the mangling of that URL or you will fight 
against it for years.

-chris

>> Вторник, 27 декабря 2022, 22:06 +03:00 от Christopher Schultz <ch...@christopherschultz.net>:
>>   
>> Fedor,
>>
>> On 12/27/22 05:55, Fedor Makarov wrote:
>>>
>>> proxy for local environment we use the js conf:
>>> proxy: {
>>>      '/api/': {
>>>        target: 'http://localhost:8080/',
>>>        changeOrigin: false,
>>>      },
>>>      '/': {
>>>        target: 'http://localhost:8080/lundase',
>>>        changeOrigin: false
>>>      }
>>>    },
>>>
>>> for normal lunch we use apache2.conf:
>>>
>>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>>
>>> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 [NC,P,L]
>>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>>
>> What you are doing is trying to remove the context-path of the
>> application through URL re-writing which will probably cause endless
>> problems during the life of your application.
>>
>> I have two possible suggestions for you:
>>
>> 1. Re-name your application from lundase to ROOT (to deploy it to /
>> instead of /lundase).
>>
>> or
>>
>> 2. Don't try to remove the /lundase URL prefix as part of your URL
>> rewriting.
>>
>> If you don't choose one or the other of these options, you will find
>> that you have many years of debugging and trying to fix up every little
>> weird thing that happens with cookies, redirects, and in-page links.
>>
>> -chris
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail:  users-help@tomcat.apache.org
>   
>   
> ---
> Fedor Makarov
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Fedor Makarov <ar...@mail.ru.INVALID>.

We have to webapps lundase and vvsguiden therefore, the options you have suggested do not look applicable on debug I saw that RequestURI in request looks like lundase/lundase/...
  
>Вторник, 27 декабря 2022, 22:06 +03:00 от Christopher Schultz <ch...@christopherschultz.net>:
> 
>Fedor,
>
>On 12/27/22 05:55, Fedor Makarov wrote:
>>
>> proxy for local environment we use the js conf:
>> proxy: {
>>     '/api/': {
>>       target: 'http://localhost:8080/',
>>       changeOrigin: false,
>>     },
>>     '/': {
>>       target: 'http://localhost:8080/lundase',
>>       changeOrigin: false
>>     }
>>   },
>>
>> for normal lunch we use apache2.conf:
>>
>> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
>>
>> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 [NC,P,L]
>> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
>> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
>> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
>
>What you are doing is trying to remove the context-path of the
>application through URL re-writing which will probably cause endless
>problems during the life of your application.
>
>I have two possible suggestions for you:
>
>1. Re-name your application from lundase to ROOT (to deploy it to /
>instead of /lundase).
>
>or
>
>2. Don't try to remove the /lundase URL prefix as part of your URL
>rewriting.
>
>If you don't choose one or the other of these options, you will find
>that you have many years of debugging and trying to fix up every little
>weird thing that happens with cookies, redirects, and in-page links.
>
>-chris
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail:  users-help@tomcat.apache.org 
 
 
---
Fedor Makarov
 

RE: Problems with requests without trailing slash Tomcat 9.0.65

Posted by alik alikov <al...@rambler.ru.INVALID>.
We have to webapps  lundase and vvsguiden therefore, the options you have suggested do not look applicable on debug I saw that RequestURI in request looks like lundase/lundase/...
27.12.2022, 22:07, Christopher Schultz < mailto:chris@christopherschultz.net chris@christopherschultz.net >
Fedor, On 12/27/22 05:55, Fedor Makarov wrote: > > proxy for local environment we use the js conf: > proxy: { >      '/api/': { >        target: ' http://localhost:8080 http://localhost:8080 /', >        changeOrigin: false, >      }, >      '/': { >        target: ' http://localhost:8080/lundase http://localhost:8080/lundase', >        changeOrigin: false >      } >    }, > > for normal lunch we use apache2.conf: > > RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/) > > RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 http://localhost:9090/rpc/invoker/$1 [NC,P,L] > RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 http://localhost:9090/api/$1 [NC,P,L] > RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 http://localhost:9090/mapi/$1 [NC,P,L] > RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 http://localhost:9090/lundase/$1 [NC,P,L] What you are doing is trying to remove the context-path of the application through URL re-writing which will probably cause endless problems during the life of your application. I have two possible suggestions for you: 1. Re-name your application from lundase to ROOT (to deploy it to / instead of /lundase). or 2. Don't try to remove the /lundase URL prefix as part of your URL rewriting. If you don't choose one or the other of these options, you will find that you have many years of debugging and trying to fix up every little weird thing that happens with cookies, redirects, and in-page links. -chris --------------------------------------------------------------------- To unsubscribe, e-mail: /compose/ users-unsubscribe@tomcat.apache.org For additional commands, e-mail: /compose/ users-help@tomcat.apache.org

Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Fedor,

On 12/27/22 05:55, Fedor Makarov wrote:
> 
> proxy for local environment we use the js conf:
> proxy: {
>      '/api/': {
>        target: 'http://localhost:8080/',
>        changeOrigin: false,
>      },
>      '/': {
>        target: 'http://localhost:8080/lundase',
>        changeOrigin: false
>      }
>    },
>   
> for normal lunch we use apache2.conf:
> 
> RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)
> 
> RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 [NC,P,L]
> RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
> RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
> RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]

What you are doing is trying to remove the context-path of the 
application through URL re-writing which will probably cause endless 
problems during the life of your application.

I have two possible suggestions for you:

1. Re-name your application from lundase to ROOT (to deploy it to / 
instead of /lundase).

or

2. Don't try to remove the /lundase URL prefix as part of your URL 
rewriting.

If you don't choose one or the other of these options, you will find 
that you have many years of debugging and trying to fix up every little 
weird thing that happens with cookies, redirects, and in-page links.

-chris


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Fedor Makarov <ar...@mail.ru.INVALID>.
proxy for local environment we use the js conf:
proxy: {
    '/api/': {
      target: 'http://localhost:8080/',
      changeOrigin: false,
    },
    '/': {
      target: 'http://localhost:8080/lundase',
      changeOrigin: false
    }
  },
 
for normal lunch we use apache2.conf:

RewriteCond %{REQUEST_URI} ^(/api/|/mapi/|/binary/|/rpc/invoker/)

RewriteRule ^/rpc/invoker/(.*)$ http://localhost:9090/rpc/invoker/$1 [NC,P,L]
RewriteRule ^/api/(.*)$ http://localhost:9090/api/$1 [NC,P,L]
RewriteRule ^/mapi/(.*)$ http://localhost:9090/mapi/$1 [NC,P,L]
#RewriteRule ^/lundase/(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
#RewriteRule ^/binary/(.*)$ http://localhost:9090/lundase/binary/$1 [NC,P,L]
#RewriteRule ^/content/(.*)$ http://localhost:9090/lundase/content/$1 [NC,P,L]
#RewriteRule ^.*/[^./]+$ $0/ [NC,R=301,L]
RewriteRule ^(.*)$ http://localhost:9090/lundase/$1 [NC,P,L]
 
ContextPath: /lundase
Ussualy we have urls of this type for example:
/lunda-online/index.html
also /lunda-online/  works correctly 
but /lunda-online without end slash  triggered redirects by with found resource /lundase/lunda-online/
and proxy in turn generates a request of this type: lundase/lundase/lunda-online
And file structure to this page 
lundase (dir) → lunda-online (dir) → index.html
 
index.html example:
<%@ page session="false"
        pageEncoding="UTF-8"
        import="com.gridnine.platform.server.lundase.web.content.*"
        import="com.gridnine.platform.common.lundase.model.content.*"
%><%
MetaVO meta = SiteMetadataHelper.getStaticMeta(MainSitePage.LUNDA_ONLINE);
%><jsp:include page="/source/frametemplates/master.jsp">
    <jsp:param name="title" value="<%= meta.getTitle() %>"/>
    <jsp:param name="description" value="<%= meta.getDescription() %>"/>
    <jsp:param name="content" value="lunda-online.jsp"/>
</jsp:include>
  
>Вторник, 27 декабря 2022, 13:42 +03:00 от Mark Thomas <ma...@apache.org>:
> 
>
>On 27/12/2022 06:25, Fedor Makarov wrote:
>>
>>
>> Tomcat 9.0.65
>> Hello I have some problems with redirects by requests without trailing slashes.
>>
>> When I try to get to the page for example: "about/page" tomcat understands that it is necessary to add a slash and adds it, however, he also adds the name of the root folder to this, that is, the url "lundase/about/page/" turns out, and any requests to our server via apache are proxied with the addition of "lundase", so it turns out that we are accessing the application on request "lundase/lundase/about/page/" which results in a 404 status.
>>
>> I googled it and found two properties:
>> context.setMapperContextRootRedirectEnabled(false)
>> context.setMapperDirectoryRedirectEnabled(false)
>> And tryed to play with them, however, it's not resolve my problem please can you help me with it?
>
><snip/>
>
>The request "/about/page" (the leading '/' is important) doesn't match
>any of the provided servlet mappings:
>
>> <url-pattern>/client-error/*</url-pattern>
>> <url-pattern>/warehouses/*</url-pattern>
>> <url-pattern>/properties-for-rent/*</url-pattern>
>> <url-pattern>/about/events/*</url-pattern>
>> <url-pattern>/ping/*</url-pattern>
>> <url-pattern>/catalogue/*</url-pattern>
>> <url-pattern>/binary/*</url-pattern>
>> <url-pattern>/content/*</url-pattern>
>> <url-pattern>/lundaprogrammet/*</url-pattern>
>> <url-pattern>/source/assets/css/aggregate.css</url-pattern>
>
>so the request will be mapped to the default servlet.
>
>The redirect will be generated (depending on the value of
>mapperDirectoryRedirectEnabled) either by the Mapper or the default
>servlet. All that affects is when the redirect is generated. The
>redirect will be the same in either case.
>
>We need to know:
>- The httpd proxy configuration
>- the context path (assumed to be "/lundase" )
>- the full URL path (you can skip the protocol, host and port) of the
>   request that triggers the problem
>
>Mark
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail:  users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail:  users-help@tomcat.apache.org
 
 
---
Fedor Makarov
 

Re: Problems with requests without trailing slash Tomcat 9.0.65

Posted by Mark Thomas <ma...@apache.org>.
On 27/12/2022 06:25, Fedor Makarov wrote:
> 
>   
> Tomcat 9.0.65
> Hello I have some problems with redirects by requests without trailing slashes.
>   
> When I try to get to the page for example: "about/page" tomcat understands that it is necessary to add a slash and adds it, however, he also adds the name of the root folder to this, that is, the url "lundase/about/page/" turns out, and any requests to our server via apache are proxied with the addition of "lundase", so it turns out that we are accessing the application on request "lundase/lundase/about/page/" which results in a 404 status.
>   
> I googled it and found two properties:
> context.setMapperContextRootRedirectEnabled(false)
> context.setMapperDirectoryRedirectEnabled(false)
> And tryed to play with them, however, it's not resolve my problem please can you help me with it?

<snip/>

The request "/about/page" (the leading '/' is important) doesn't match 
any of the provided servlet mappings:

> <url-pattern>/client-error/*</url-pattern>
> <url-pattern>/warehouses/*</url-pattern>
> <url-pattern>/properties-for-rent/*</url-pattern>
> <url-pattern>/about/events/*</url-pattern>
> <url-pattern>/ping/*</url-pattern>
> <url-pattern>/catalogue/*</url-pattern>
> <url-pattern>/binary/*</url-pattern>
> <url-pattern>/content/*</url-pattern>
> <url-pattern>/lundaprogrammet/*</url-pattern>
> <url-pattern>/source/assets/css/aggregate.css</url-pattern>

so the request will be mapped to the default servlet.

The redirect will be generated (depending on the value of 
mapperDirectoryRedirectEnabled) either by the Mapper or the default 
servlet. All that affects is when the redirect is generated. The 
redirect will be the same in either case.

We need to know:
- The httpd proxy configuration
- the context path (assumed to be "/lundase" )
- the full URL path (you can skip the protocol, host and port) of the
   request that triggers the problem

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org