Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 on requests without trailing slash to i18n urls

Tags:

python

django

Because of the APPEND_SLASH = True setting all requests with "/whatever/path" will be redirected to "/whatever/path/".

BUT urls definded within a i18n_patterns() don't redirect for some reason

even the test works:

./runtests.py --settings=test_sqlite i18n.URLRedirectWithoutTrailingSlashTests
like image 270
fetzig Avatar asked Nov 11 '11 10:11

fetzig


People also ask

Should you have a trailing slash at the end of URLs?

A trailing slash at the end of a URL on your website can cause issues with duplicate content if not dealt with correctly. Put simply, Google doesn't like seeing the same content on different pages. It can be confusing for both search engines and users.

Does Google care about trailing slash?

Google does not care whether or not you use a trailing slash in your URLs. The thing that does matter is how you use them – Google counts each one as a different URL. https://www.example.com/safari and https://www.example.com/safari/ are two individual pages.

What is a trailing slash in URL?

Historically, it's common for URLs with a trailing slash to indicate a directory, and those without a trailing slash to denote a file: http://example.com/foo/ (with trailing slash, conventionally a directory) http://example.com/foo (without trailing slash, conventionally a file)

Why is there a at end of URL?

Conventionally, a trailing slash (/) at the end of a URL meant that the URL was a folder or directory. At the same time, a URL without a trailing slash at the end used to mean that the URL was a file. However, this isn't how many websites are structured today.


1 Answers

it doesn't work properly if the middleware's aren't in order.

see: https://docs.djangoproject.com/en/1.5/topics/i18n/translation/#how-django-discovers-language-preference

that's how it should look like:

MIDDLEWARE_CLASSES = (
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.locale.LocaleMiddleware',
   'django.middleware.common.CommonMiddleware',
   ...
)
like image 195
fetzig Avatar answered Oct 08 '22 16:10

fetzig