Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django URL // double slash being dropped (Possibly Apache's fault)?

I have a url with a pattern like so:

('^(?i)somewhere/(\d+)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$', somewherePage),

where it should pick up a URL like:

http://foo.com/somewhere/1337/foo/params/that/are//maybe///used/

Notice how some of the parameters are not present and result in //. This has stopped working and instead of the correct url I am getting something like:

http://foo.com/somewhere/1337/foo/params/that/are/maybe/used/

where the needed slashes are not there and my pattern is then not recognized. I think this may be caused by something my apache web server is doing but I am not how to figure this out.

My question is how can I stop the extra slashes from being removed or is there another solution for having a dynamic number of parameters. Also this code used to work fine but has sense stopped. I am unsure what has changed as the code base is legacy but I know this way of passing a variable number of parameters has worked.

like image 928
Andrew Hubbs Avatar asked Feb 25 '23 03:02

Andrew Hubbs


2 Answers

is there another solution for having a dynamic number of parameters

Yes, it's called a query string. Instead of that ugly pattern use a simpler one (one that matches required parameters), and pass everything else after ?, e.g. example.com/foo/42?p1=foo&p2=bar. You can then extract them from request.GET.

like image 97
Cat Plus Plus Avatar answered Mar 05 '23 15:03

Cat Plus Plus


I've ran into this question after debugging a similar issue on Django. The extra slash was always dropped due to nginx. Adding a merge_slashes off in nginx configuration fixed the issue.

like image 35
Ariod Avatar answered Mar 05 '23 16:03

Ariod