The question may have been asked many times, but I couldn't find something about this which is a basic stuff to do. I have a problem with my website one of the sub urls of google search redirects to the wrong page.
Here are the urls :
www.example.com/login/user/ #wrong url
www.example.com/accounts/login/ #correct url
urls.py : url(r'^accounts/login/$', auth_views.login, name='login'),
I'd like the user to be redirected to the correct url if he access the wrong one. I know that it is possible to do that with views using redirect(reverse('...')) but doing it just for this purpose doesn't sound like the best way.
Is there a way to redirect an user when he enters a wrong url to another one only by using urls.py ?
You would normally do this on your webserver, e.g. Apache
RewriteRule /login/user/ /accounts/login/ [R=301,L]
That way you don't need to load Django to do a static redirect (you might build up a longer list of these as site-designs evolve).
To urls.py, you can add:
url(r'^login/user/$', auth_views.login, name='login')
It seems like you are aware of that. Did I not understand your question?