4

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.

2
  • Are you asking about the docs.djangoproject.com/en/dev/ref/settings/#append-slash setting? Commented Mar 25, 2010 at 21:28
  • Turns out that I'm actually looking for an Apache solution, because currently when the user goes to /train nothing is forwarded to my Django code. Thanks for your comment. Commented Mar 27, 2010 at 11:43

3 Answers 3

6

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
Sign up to request clarification or add additional context in comments.

1 Comment

Finally a solution! Thank you very much!
6

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/

Comments

0

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

1 Comment

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.