Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!