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?开发者_StackOverflow中文版
Thanks.
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
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/
Set your urlconf to accept train/
as valid instead, then make train
lead to a generic redirect to /train/
.
精彩评论