Make apache and django add trailing slash

My / train directory script alias in httpd.conf: WSGIScriptAlias ​​/train/some-path/../django.wsgi

And it works well, except for one problem. If the user goes / trains (without a slash), he does not redirect him to / train /, but simply gives him the correct page. This is a problem because in this way the relative links on this page lead to the wrong place when you did not use a slash to access it.

How can this be solved?

Thanks.

+4
source share
3 answers

I use something like this for redirecting / training / training /, what I am doing is redirecting the whole URL, which does not end with / to / train /.

<Location "/train"> Order deny,allow Allow from all RewriteEngine on RewriteRule !^.*/$ /train/ [R] </Location> WSGIScriptAlias /train /some-path/../django.wsgi 
+6
source

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

 RedirectMatch ^/train$ /train/ 
+6
source

Set urlconf to accept train/ as valid instead, then make train result in a general redirect to /train/ .

0
source

Source: https://habr.com/ru/post/1305157/


All Articles