You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by lightbulb432 <ve...@hotmail.com> on 2007/01/13 11:29:28 UTC

Trailing slash added

I noticed that Tomcat adds a trailing slash automatically when it detects
that the requested resource points to an existing directory. While I know
that Apache web server offers plenty of configuration options to control and
customize this behavior, I'm unfamiliar with similar customization
capability within Tomcat. (Where is this trailing slash behavior specified
for Tomcat? Or is it a compiled-in setting function that cannot be changed?)

How can I customize this and other Apache-like settings? Is the only option
to front Tomcat with Apache?
-- 
View this message in context: http://www.nabble.com/Trailing-slash-added-tf2970832.html#a8312974
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Re: Trailing slash added

Posted by Len Popp <le...@gmail.com>.
I was talking about what the browser does when you click on a link in
a web page.
Suppose you have a web page called
http://www.example.com/directory/page1.html and it contains this
hyperlink:
  <a href="page2.html">Page 2</a>
When you click on that link, the browser has to figure out what
"page2.html" refers to. It's relative to the current page, so the
browser will request http://www.example.com/directory/page2.html.

Now suppose the page containing that link is
"http://www.example.com/directory/". The trailing "/" means that this
is logically a directory so when you click on that link the browser
requests http://www.example.com/directory/page2.html (same as before).

Now remove the trailing slash, so the web page's URL is
"http://www.example.com/directory". To the browser, this looks like a
file called "directory" in the directory "/". So when you click on the
Page 2 link you'll get http://www.example.com/page2.html which is
wrong.

That's why web servers don't treat http://www.example.com/directory/
and http://www.example.com/directory as the same thing - if they did,
relative links would sometimes fail, depending how you typed the URL
into the browser. Instead, as a convenience for those of us who are
too lazy to type the trailing "/", the web server will make sure the
URL ends with a "/" by sending a redirect response to force the
browser to fetch the correct URL.
-- 
Len

On 1/15/07, lightbulb432 <ve...@hotmail.com> wrote:
>
> Could anyone please expand a little more on what's meant by the two
> statements below?
>
>
> Len Popp wrote:
> >
> > It doesn't matter if it's done by URLRewriteFilter or some other
> > method because it's the browser that interprets the relative URLs, not
> > the server.
> >
>
>
>
> > If the containing page's URL looks like a file when it's
> > really a directory, the browser will get them wrong.
> >
> --
> View this message in context: http://www.nabble.com/Trailing-slash-added-tf2970832.html#a8378938
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

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


Re: Trailing slash added

Posted by Len Popp <le...@gmail.com>.
I think Rashmi and I mean the same thing by "translation" and "resolution".
Yes, the browser does the URL resolution, and if you have relative
URLs then the trailing slash is meaningful. If you remove it you will
change the meaning of relative URLs on that page.
-- 
Len

On 1/17/07, lightbulb432 <ve...@hotmail.com> wrote:
>
> I want to get rid of the trailing slash for style issues (really a small
> concern) and also to learn about customization within Tomcat as well as URL
> rewriting.
>
> Regarding URL rewriting, did you mean the following?
>
>     <rule>
>         <note>Testing trailing slash.</note>
>         <from>(.*)/</from>
>         <to>$1</to>
>     </rule>
>
> Perhaps that works rather than a <to> value of (.*)
>
> Are you sure about what you said: "URL Rewriting will not help in
> eliminating the trailing slash because it's the browser that does the URL
> translation." The way I interpreted Len's comments were that it's the server
> that does the URL creation/translation, and the browser that does URL
> resolution...two different concepts...
>
>
>
> Rashmi Rubdi wrote:
> >
> > Could you explain to us, why you want to get rid of the trailing slash ?
> >
> >
> >>Could anyone please expand a little more on what's meant by the two
> >>statements below?
> >
> >>>Len Popp wrote:
> >>>
> >>> It doesn't matter if it's done by URLRewriteFilter or some other
> >>> method because it's the browser that interprets the relative URLs, not
> >>> the server.
> >>>
> >
> > URLRewriteFilter is an application that allows you to rewrite URLs, that
> > means, for example if you have a URL like
> > http://localhost:8080/page.jsp?param1=499&param2=333  , with URL
> > rewriting you can represent it anyway you want with a regular expession
> > pattern
> > that means you can represent it like this
> >
> > http://localhost:8080/page/499/333/  , or any other pattern.
> >
> >
> > But what Len is saying (and I verified that he's right), is that URL
> > Rewriting will not help in eliminating the trailing slash because it's the
> > browser that does the URL translation.
> >
> > I tried URL rewriting with this pattern to test your case:
> >     <rule>
> >         <note>Testing trailing slash.</note>
> >         <from>(.*)/</from>
> >         <to>(.*)</to>
> >     </rule>
> >
> > When I tried http://localhost:8080   , instead of http://localhost:8080/
> > it didn't work, just showed a blank screen.
> >
> > I had to delete the URL rewriting rule, only after that it worked.
> >
> >> If the containing page's URL looks like a file when it's
> >> really a directory, the browser will get them wrong.
> >>
> > --
> >
> >
> >
> > ____________________________________________________________________________________
> > Now that's room service!  Choose from over 150,000 hotels
> > in 45,000 destinations on Yahoo! Travel to find your fit.
> > http://farechase.yahoo.com/promo-generic-14795097
> >
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Trailing-slash-added-tf2970832.html#a8413297
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

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


Re: Trailing slash added

Posted by lightbulb432 <ve...@hotmail.com>.
I want to get rid of the trailing slash for style issues (really a small
concern) and also to learn about customization within Tomcat as well as URL
rewriting.

Regarding URL rewriting, did you mean the following?

    <rule>
        <note>Testing trailing slash.</note>
        <from>(.*)/</from>
        <to>$1</to>
    </rule>

Perhaps that works rather than a <to> value of (.*)

Are you sure about what you said: "URL Rewriting will not help in
eliminating the trailing slash because it's the browser that does the URL
translation." The way I interpreted Len's comments were that it's the server
that does the URL creation/translation, and the browser that does URL
resolution...two different concepts...



Rashmi Rubdi wrote:
> 
> Could you explain to us, why you want to get rid of the trailing slash ?
> 
> 
>>Could anyone please expand a little more on what's meant by the two
>>statements below?
> 
>>>Len Popp wrote:
>>> 
>>> It doesn't matter if it's done by URLRewriteFilter or some other
>>> method because it's the browser that interprets the relative URLs, not
>>> the server. 
>>>
> 
> URLRewriteFilter is an application that allows you to rewrite URLs, that
> means, for example if you have a URL like
> http://localhost:8080/page.jsp?param1=499&amp;param2=333  , with URL
> rewriting you can represent it anyway you want with a regular expession
> pattern
> that means you can represent it like this
> 
> http://localhost:8080/page/499/333/  , or any other pattern.
> 
> 
> But what Len is saying (and I verified that he's right), is that URL
> Rewriting will not help in eliminating the trailing slash because it's the
> browser that does the URL translation.
> 
> I tried URL rewriting with this pattern to test your case:
>     <rule>
>         <note>Testing trailing slash.</note>
>         <from>(.*)/</from>
>         <to>(.*)</to>
>     </rule> 
> 
> When I tried http://localhost:8080   , instead of http://localhost:8080/ 
> it didn't work, just showed a blank screen.
> 
> I had to delete the URL rewriting rule, only after that it worked.
> 
>> If the containing page's URL looks like a file when it's
>> really a directory, the browser will get them wrong.
>> 
> --
> 
> 
>  
> ____________________________________________________________________________________
> Now that's room service!  Choose from over 150,000 hotels
> in 45,000 destinations on Yahoo! Travel to find your fit.
> http://farechase.yahoo.com/promo-generic-14795097
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Trailing-slash-added-tf2970832.html#a8413297
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Re: Trailing slash added

Posted by lightbulb432 <ve...@hotmail.com>.
Could anyone please expand a little more on what's meant by the two
statements below?


Len Popp wrote:
> 
> It doesn't matter if it's done by URLRewriteFilter or some other
> method because it's the browser that interprets the relative URLs, not
> the server. 
> 



> If the containing page's URL looks like a file when it's
> really a directory, the browser will get them wrong.
> 
-- 
View this message in context: http://www.nabble.com/Trailing-slash-added-tf2970832.html#a8378938
Sent from the Tomcat - User mailing list archive at Nabble.com.


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


Re: Trailing slash added

Posted by Tim Funk <fu...@joedog.org>.
There is no way to customize this behavior other than overriding the 
default servlet with your own implementation.

-Tim

lightbulb432 wrote:
> I noticed that Tomcat adds a trailing slash automatically when it detects
> that the requested resource points to an existing directory. While I know
> that Apache web server offers plenty of configuration options to control and
> customize this behavior, I'm unfamiliar with similar customization
> capability within Tomcat. (Where is this trailing slash behavior specified
> for Tomcat? Or is it a compiled-in setting function that cannot be changed?)
> 
> How can I customize this and other Apache-like settings? Is the only option
> to front Tomcat with Apache?


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