Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

294
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda