Search code examples
regexdjangourl-pattern

url pattern working different behaviour between dev and prod - Django


I'm having a problem with Django urlconf.

Basically I've this pattern:

^publication/(?P<pub_search>[\w\.=&]+)?(/keyword/(?P<key_search>[\w=&]+))?(/author/(?P<auth_search>[\w=&]+))?(/tag/(?P<tag_search>[\w=&]+))?(/from/(?P<from_date>[\w\d=&]+))?(/until/(?P<until_date>[\w\d=&]+))?$

According this pattern, I should be able to have an URL of this form:

http://127.0.0.1:8000/publication//author/name=crock

Indeed this url form is recognized in my django dev server. But on the production server (Apache + mod_wsgi) it doesn't match the url.

I've no idea of the reason why it acts this way on prod server.

Cheers


Solution

  • Apache removes multiple slashes inside the path. You can fix this with some mod_rewrite magic.

    Quoting from here:

    RewriteCond %{THE_REQUEST} ^GET\ /(https?://[^\s]+)
    RewriteRule ^https?:/ index.php?url=%1 [L]