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

340
Visualizações
how to manage Django urls alias redirections?

I'd like set up my urls correctly avoiding doing it like the example below since it afects my Google indexation :

urls.py (wrong way) :

url(r'^virtual-reality/$', views.virtualreality, name="virtual-reality"),
url(r'^virtual-reality$', views.virtualreality, name="virtual-reality"),
url(r'^vr/$', views.virtualreality, name="virtual-reality"),
url(r'^vr$', views.virtualreality, name="virtual-reality"),

As you can see I'd like vr/, vr, virtual-reality/, virtual-reality to redirect to the same page. I have more than 30 urls on my site and doing each url redirection like this is problematic since the structure grows.

I do not use Apache on my Django site, so Rewriting Rules can not be made. (I'm on pythonanywhere (webserver : Gunicorn))

What's the best way to redirect all types of aliases in the same view without affecting my google search indexation and avoid to enter each url with the same view to urls.py ?

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Best way to do it is using django redirect app https://docs.djangoproject.com/en/1.10/ref/contrib/redirects/ you can easily manage redirects from the admin with this.

over 4 years ago · Santiago Trujillo Relatório

0

Another way to solve the trailing slash problem, is to use ? flag in the regex.

url(r'^virtual-reality/?$', views.virtualreality, name="virtual-reality"),
url(r'^vr/?$', views.virtualreality, name="virtual-reality"),

If using CommonMiddleware, it adds the trailing slash and return the view with it (if the version without the trailing slash is not found in any urlpattern). It can be seen in the documentation.

over 4 years ago · Santiago Trujillo Relatório

0

urls.py is Python after all

Just write a suitable data structure that can capture what you want and use a loop to generate the list containing the url() calls from that.

over 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