Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Django URLs work with or without /

Tags:

python

django

I have a django app that has / at the end of every URL conf. Example:

# user home page
(r'^home/$', 'user_home_page'),

However, I'm noticing this is causing a ton of redirects on my server, because when people dont add the /, it redirects them. Is there any way to have it accept both without a redirect except doing:

# user home page
(r'^home$', 'user_home_page'),
(r'^home/$', 'user_home_page'),

or should I avoid URL confs like that?

like image 764
Brenden Avatar asked Jan 16 '12 20:01

Brenden


1 Answers

While you can accept both without doing a redirect by using:

(r'^home/?$', 'user_home_page'),

It is not best SEO practice because it will look like you have duplicate content and your hits will be split between the two pages.

like image 112
zackdever Avatar answered Oct 01 '22 01:10

zackdever