Discussion:
Making trailing slashes unnecessary.
Lloyd Zusman
2005-09-19 13:29:11 UTC
Permalink
Forgive me if this question has been answered here before, but my
search in the list archives for "trailing" and "slash" yielded nothing.

If I have a webapp called "example" on my snakelets-powered site. This
site is a virtual host named "site.com". With this, I can access that
webapp
as follows:

http://site.com/example/

Note the trailing slash. If, on the other hand, I access the site as
follows,
I get error 404:

http://site.com/example

In other words, the trailing slash is necessary. However, I don't want
people who access the site to have to remember to code the trailing slash,
nor do I want them to access the site with an explicit "/index.y" in the
URL.

Is there any way to configure this webapp so that it functions the same
both with and without the trailing slash in the URL?

The way I set up the "example" webapp is as follows:

- I create an "example" subdirectory in my "webapps" directory.

- I put an "index.y" file into this "example" subdirectory. This file
contains the code for my webapp.

- I put an appropriate __init__.py file into the "example" subdirectory.

- I list "example" as one of the data values pointed to by the key
"site.com" in the "virtualhosts" map in the __init__.py file in the
"webapps" directory.

I'm hoping that I'm missing something in this setup that will cause the
trailing slash to no longer be mandatory.

Any ideas?

Thanks in advance.
--
Lloyd Zusman
ljz-CfBCfuhdJ+DQT0dZR+***@public.gmane.org
God bless you.




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Irmen de Jong
2005-09-19 19:21:22 UTC
Permalink
Post by Lloyd Zusman
Forgive me if this question has been answered here before, but my
search in the list archives for "trailing" and "slash" yielded nothing.
If I have a webapp called "example" on my snakelets-powered site. This
site is a virtual host named "site.com". With this, I can access that
webapp
http://site.com/example/
Note the trailing slash. If, on the other hand, I access the site as
follows,
http://site.com/example
Yes.

The general idea is that Snakelets tries to find a page in the ROOT WEBAPP
that satiesfies your "example" url path component.
Something like "example.html" or "example.y".

If that page doesn't exist, you get an error. Snakelets does not "look further",
i.e. it does not start looking for webapps that might satisfy the name.

There is a solution that works right now:
make a page "example.y" in your ROOT webapp, and just put a http redirect
to "/example/" in it (with a trailing slash).

But I agree that Snakelets should probably be more intelligent, and I think
it should indeed start looking for webapps that satisfy the name if no page
can be found. I'll think about this, perhaps I will implement this.

--Irmen



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Lloyd Zusman
2005-09-19 22:45:55 UTC
Permalink
[ ... ]
Note the trailing slash. If, on the other hand, I access the site as
follows,
http://site.com/example
[ ... ]
make a page "example.y" in your ROOT webapp, and just put a http redirect
to "/example/" in it (with a trailing slash).
But I agree that Snakelets should probably be more intelligent, and I think
it should indeed start looking for webapps that satisfy the name if no page
can be found. I'll think about this, perhaps I will implement this.
--Irmen
Well, this trick about putting example.y into ROOT works just fine.

Hmm ... or to avoid the cost of a redirect, I guess that the examply.y
file in ROOT could just be a symbolic link which points to index.y in
the webapps/example directory.

Of course, if you ever do want to fix this, I'll certainly be an
appreciative user! :)

A suggestion: for efficiency, perhaps this can be controlled by a
configuration directive in __init__.py: if a name is somehow flagged in
that file, it won't be searched for in ROOT at all, and it will simply
be looked up as a webapp, whether or not there is a trailing slash.

Just a thought ...

In any case, thanks!
--
Lloyd Zusman
ljz-CfBCfuhdJ+DQT0dZR+***@public.gmane.org
God bless you.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Irmen de Jong
2005-09-19 23:04:29 UTC
Permalink
Post by Lloyd Zusman
Hmm ... or to avoid the cost of a redirect, I guess that the examply.y
file in ROOT could just be a symbolic link which points to index.y in
the webapps/example directory.
No, don't do this. You will screw up your relative urls.

Say your webapps/example/index.y contains menu links like
a href="item1" , a href="item2"

If you access the page using http://host/example;
they will point to
http://host/item1 , http://host/item2

instead of
http://host/example/item1 , http://host/example/item2



Also the cost of the redirect is only once, when opening the first
page of the site. After that, all accesses are done with the
"correct" url...


--Irmen


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Lloyd Zusman
2005-09-19 23:18:04 UTC
Permalink
Post by Irmen de Jong
Post by Lloyd Zusman
Hmm ... or to avoid the cost of a redirect, I guess that the examply.y
file in ROOT could just be a symbolic link which points to index.y in
the webapps/example directory.
No, don't do this. You will screw up your relative urls.
Oh ... OK. Thanks.
Post by Irmen de Jong
Also the cost of the redirect is only once, when opening the first
page of the site. After that, all accesses are done with the
"correct" url...
I didn't realize that.

I'm now redirecting via self.Yhttpredirect(url). With this routine, is
the redirect cost only incurred once? ... or do I have to use
self.Yredirect(url) or possibly something else?

Thanks.
--
Lloyd Zusman
ljz-CfBCfuhdJ+DQT0dZR+***@public.gmane.org
God bless you.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Irmen de Jong
2005-09-19 23:57:08 UTC
Permalink
Post by Lloyd Zusman
Post by Irmen de Jong
Also the cost of the redirect is only once, when opening the first
page of the site. After that, all accesses are done with the
"correct" url...
I didn't realize that.
I'm now redirecting via self.Yhttpredirect(url). With this routine, is
the redirect cost only incurred once? ...
Depends, if it is no longer needed to redirect from the new url location,
the redirection is ofcourse only done once, when the first page loads.
Usualla a http-redirect is reasonably fast too.
Post by Lloyd Zusman
or do I have to use
self.Yredirect(url) or possibly something else?
If you are sure about the validity of your urls in the page,
it's faster to use internal redirection instead of http-redirection.
It saves a http-response and a new http-request.
However as the web browser still thinks it is on the "original"
page, you will have to be damn sure that the urls in the page that
you are internally redirecting to, are valid in that context.

I often only use http-redirection to make sure that the web browser
is in the base url location that I want it to be ;-)



BTW, I've implemented the trailing-slash-auto-appending for webapps.
It's in CVS, and you can see it in action on my site:
Try: http://www.razorvine.net/snake/frog
it should redirect you to http://www.razorvine.net/snake/frog/

If a page exists in the root webapp with the same name, the page
is shown instead.

--Irmen


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Lloyd Zusman
2005-09-20 00:09:37 UTC
Permalink
Post by Irmen de Jong
[ ... ]
I'm now redirecting via self.Yhttpredirect(url). With this routine, is
the redirect cost only incurred once? ...
Depends, if it is no longer needed to redirect from the new url location,
the redirection is ofcourse only done once, when the first page loads.
Usualla a http-redirect is reasonably fast too.
or do I have to use
self.Yredirect(url) or possibly something else?
If you are sure about the validity of your urls in the page,
it's faster to use internal redirection instead of http-redirection.
I guess that Yredirect(url) is the "internal" redirection. Thanks.
Post by Irmen de Jong
[ ... ]
I often only use http-redirection to make sure that the web browser
is in the base url location that I want it to be ;-)
Yes, me too. But in this case, using Yredirect(url) will leave
"http://site.com/example" (no trailing slash) in my browser's address
window, which is sometimes what I want.
Post by Irmen de Jong
BTW, I've implemented the trailing-slash-auto-appending for webapps.
Try: http://www.razorvine.net/snake/frog
it should redirect you to http://www.razorvine.net/snake/frog/
If a page exists in the root webapp with the same name, the page
is shown instead.
Wow! That was a quick implementation!

Yes, your page indeed redirected correctly.

Is it safe to install the CVS implementation tonight? I know that in
the past, that version was sometimes a work in progress.

Thanks again! :)
--
Lloyd Zusman
ljz-CfBCfuhdJ+DQT0dZR+***@public.gmane.org
God bless you.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Lloyd Zusman
2005-09-20 00:30:26 UTC
Permalink
[ ... ]
BTW, I've implemented the trailing-slash-auto-appending for webapps.
[ ... ]
Is it safe to install the CVS implementation tonight? I know that in
the past, that version was sometimes a work in progress.
By the way, I just did a cvs update, but there were no changes in the
snakeserver directory since the 1.42 release except for a few error
message improvements. Are you sure that you committed these auto-slash
changes?
--
Lloyd Zusman
ljz-CfBCfuhdJ+DQT0dZR+***@public.gmane.org
God bless you.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Irmen de Jong
2005-09-20 00:55:01 UTC
Permalink
Post by Lloyd Zusman
By the way, I just did a cvs update, but there were no changes in the
snakeserver directory since the 1.42 release except for a few error
message improvements. Are you sure that you committed these auto-slash
changes?
Yes. Sourceforge always has a delay of 0 to 2 days on the public CVS server.
Try again tomorrow ;-)

As 1.42 has just been tagged and committed, its safe to grab the CVS version.
Its only newer by 1 or 2 days now and contains only a few changes so far
(including the slash thingy).

--Irmen


P.S.
I could implement it so quickly because I just had to add a few lines
of code to the GET/HEAD/POST handlers. They look for a page processor
for the given URL. If they could not find one, I added a line to test
if there would be a webapp with that name to redirect to (appending
a slash). That was all ;)

P.P.S.
If you're adventurous and/or helpful, it is always nice to have other
people also run the current CVS development version (for testing purposes).
This way possible problems get discovered sooner ....


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Lloyd Zusman
2005-09-20 08:32:23 UTC
Permalink
Post by Irmen de Jong
Post by Lloyd Zusman
By the way, I just did a cvs update, but there were no changes in the
snakeserver directory since the 1.42 release except for a few error
message improvements. Are you sure that you committed these auto-slash
changes?
Yes. Sourceforge always has a delay of 0 to 2 days on the public CVS server.
Try again tomorrow ;-)
Yes, it's there now. The changes work fine. Thanks!
Post by Irmen de Jong
As 1.42 has just been tagged and committed, its safe to grab the CVS version.
Its only newer by 1 or 2 days now and contains only a few changes so far
(including the slash thingy).
--Irmen
P.S.
I could implement it so quickly because I just had to add a few lines
of code to the GET/HEAD/POST handlers. They look for a page processor
for the given URL. If they could not find one, I added a line to test
if there would be a webapp with that name to redirect to (appending
a slash). That was all ;)
I see the change, and I'm curious about something: why are you using an
http redirect in this case, and not just an internal redirect?
Post by Irmen de Jong
P.P.S.
If you're adventurous and/or helpful, it is always nice to have other
people also run the current CVS development version (for testing purposes).
This way possible problems get discovered sooner ....
I always used to use the CVS version until one time recently, when there
was something in CVS which broke frog. That's why I asked last night if
it's safe to use it.

But now, I'm back with CVS, and as I mentioned above, it's working
with no problems.

Thanks again!
--
Lloyd Zusman
ljz-CfBCfuhdJ+DQT0dZR+***@public.gmane.org
God bless you.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Irmen de Jong
2005-09-20 17:43:10 UTC
Permalink
Post by Lloyd Zusman
I see the change, and I'm curious about something: why are you using an
http redirect in this case, and not just an internal redirect?
Because I modeled it after the way Snakelets treats directories;
it auto-appends a trailing slash when you omit it on a directory name
in the URL.
Also it solves any problems that may occur regarding relative URLs
in the index page, as I explained in the previous post.
Post by Lloyd Zusman
I always used to use the CVS version until one time recently, when there
was something in CVS which broke frog. That's why I asked last night if
it's safe to use it.
Yes, but this is natural. While I often try to be backwards compatible,
sometimes there are changes that break old code. Some are intentional,
some aren't, and thats' why it's handy if more than one person runs
the current CVS version ;)

--Irmen


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Lloyd Zusman
2005-09-20 21:02:45 UTC
Permalink
Post by Irmen de Jong
Post by Lloyd Zusman
I see the change, and I'm curious about something: why are you using an
http redirect in this case, and not just an internal redirect?
Because I modeled it after the way Snakelets treats directories;
it auto-appends a trailing slash when you omit it on a directory name
in the URL.
Also it solves any problems that may occur regarding relative URLs
in the index page, as I explained in the previous post.
Oh ... I thought the relative URL problem only concerned symbolic links
... but now I understand better.
Post by Irmen de Jong
Post by Lloyd Zusman
I always used to use the CVS version until one time recently, when there
was something in CVS which broke frog. That's why I asked last night if
it's safe to use it.
Yes, but this is natural. While I often try to be backwards compatible,
sometimes there are changes that break old code. Some are intentional,
some aren't, and thats' why it's handy if more than one person runs
the current CVS version ;)
Yes, that is natural, and that is why it was natural for me to enquire
if the use of CVS was "safe" at the moment. :)

All is well ... all works great ... and thanks for all your work
and explanations concerning this issue!

... and thanks again for Snakelets!
--
Lloyd Zusman
ljz-CfBCfuhdJ+DQT0dZR+***@public.gmane.org
God bless you.



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Fred Pacquier
2005-09-20 19:37:38 UTC
Permalink
Post by Irmen de Jong
BTW, I've implemented the trailing-slash-auto-appending for webapps.
Try: http://www.razorvine.net/snake/frog
it should redirect you to http://www.razorvine.net/snake/frog/
If a page exists in the root webapp with the same name, the page
is shown instead.
Hey thanks for that ! (and to Lloyd for prompting the change...)
This is something that had been (moderately) irking me too, right from
the beginning :)


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Loading...