I would like to make urls of my site case-insensitive. As I
understand, by default the url matching is case-sensitive. Is there a
way to specify in my urls.py that I want a case-insensitive match?
Thanks,
Ram
I haven't tried it, but I think that you could just use regular
expression extension notation to make the regex case insensitive in
your url conf.
So instead of:
('users/add/', 'views.add'),
You'd do:
('(?i)users/add/', 'views.add'),
Try it and let everyone know if that works...
On Jun 2, 1:35 pm, Ramashish Baranwal <ramashish.li...@gmail.com>
wrote:
urls.py:
from django.conf.urls.defaults import *
import re
re_admin = re.compile(r'^admin/', re.I)
urlpatterns = patterns('',
(re_admin, include('django.contrib.admin.urls')),
)
This will allow a match for any case: /admin/, /aDmiN/, /ADMIN/
Therefore, rather than configuring urls.py to ignore case, a better
solution would be to use mod_rewrite to map the "wrong case" URLs to
the correct ones.
For example, you could configure mod_rewrite to convert all URLs to
lowercase.
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteRule ^/(.*)$ /${lowercase:$1}
Hope this helps.
Bryan
On Jun 1, 6:35 pm, Ramashish Baranwal <ramashish.li...@gmail.com>
wrote:
> Hi,
>
> I would like to makeurlsof my sitecase-insensitive. As I
> understand, by default the url matching iscase-sensitive. Is there a