Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

295
Vistas
Django alias redirect on wrong url to the correct url

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 ?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

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

about 4 years ago · Santiago Trujillo Denunciar

0

One solution is to use the RedirectView inside urls.py as shown here in the docs

So, for example:

url(r'^login/user$', RedirectView.as_view(pattern_name='login')),
about 4 years ago · Santiago Trujillo Denunciar

0

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?

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda