Search code examples
djangoapachewsgitrailing

making apache and django add a trailing slash


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.


Solution

  • 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