views:

291

answers:

3

Hello.

My /train directory is aliased to a script in httpd.conf by: WSGIScriptAlias /train /some-path/../django.wsgi

And it works well, except for one problem. If a user goes to /train (with no trailing slash) it will not redirect him to /train/, but will just give him the right page. This is a problem because this way the relative links on this page lead to the wrong place when no trailing slash was used to access it.

How can this be worked out?

Thanks.

A: 

Set your urlconf to accept train/ as valid instead, then make train lead to a generic redirect to /train/.

Ignacio Vazquez-Abrams
Thanks, but Django can't tell if the user went to train or to train/ because both are detected by the pattern "^$" because the Apache server redirects only /train/(.*) to Django.I guess the solution has to be in httpd.conf and not in Django, at least if I want to make my Django code independent of the containing directory (that is - changing /train/ to some other name in httpd.conf should be the only thing to do if I want to change the directory name).
+1  A: 

I'm using something like this for redirecting /train to /train/, what I do is redirecting all the URL than doesn't end with / to /train/.

<Location "/train">
     Order deny,allow
     Allow from all
     RewriteEngine on
     RewriteRule  !^.*/$  /train/  [R]
</Location>

WSGIScriptAlias /train /some-path/../django.wsgi
Ferran
Finally a solution! Thank you very much!
A: 

If you just need to redirect from /train to /train/ and not from every subdirectory without a trailing slash, then there's a simpler solution using the RedirectMatch directive:

RedirectMatch ^/train$ /train/
baumratte