Reputation: 1867
NOTE / EDIT: As I've learnt, the default behaviour is ok SEO wise (one redirect is allowed...multiple is no good). So this is a bit of an overkill.
If my django-cms site is multilingual, visiting domain.com
always redirects to domain.com/default-language/
.
Is there a preferred way/package to make this behaviour go away?
Reason I want it are mainly because of SEO. Best solution would be:
domain.com
=> no redirect
domain.com/default-lang/
=> redirect back to domain.com
domain.com/other-lang/
=> stay as is, as there is translated content
Example: http://www.parkhotel-bellevue.ch does it correctly, now.http://www.parkhotel-bellevue.ch/
redirects to http://www.parkhotel-bellevue.ch/de/
, which is what I dont want.
NOTE: this question is about django-cms, not django alone.
Upvotes: 3
Views: 659
Reputation: 3242
What if you put your Index
url in root conf, and all your other pages under i18n_patterns
?
urlpatterns = [
url(r'^$', Index.as_view(), name='index'),
]
urlpatterns += i18n_patterns('',
url(r'^', include('cms.urls')),
)
This way, your root URL won't redirect to language specific URL.
For the second part of your question, you could try the following solutions:
Index
view in your i18n_patterns
as well could do the trickSomething like:
# views.py
class Index(View):
def dispatch(self, request, *args, **kwargs):
if request.path != '/':
return redirect('/')
return super().dispatch(request, *args, **kwargs)
# urls.py
urlpatterns = [
url(r'^$', Index.as_view(), name='index'),
]
urlpatterns += i18n_patterns('',
url(r'^$', Index.as_view(), name='index'),
url(r'^', include('cms.urls')),
)
EDIT:
Another option could be to use your own LocaleMiddleware
by subclassing the one from django.
The redirection part seems to happen here: https://github.com/django/django/blob/master/django/middleware/locale.py#L29
Upvotes: 1