On my local test machine it works fine, but on the server it will double GET parameters.
For example, with this code:
return redirect('/add?c='+str(rm.id))
I end up at /add?c=3423?c=3423 for example.
And
return redirect('/add?success')
Gets me to /add?success?success
Does anyone know what’s up?
EDIT: Here’s my relevant line of urls.py and my nginx config
url(r'^add/$', 'rumors.views.add'),
server{
listen 0.0.0.0:443 ssl;
server_name www.****.com ****.com;
ssl_certificate /opt/etc/***;
ssl_certificate_key /opt/etc/***;
keepalive_timeout 70;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
auth_basic "Restricted";
auth_basic_user_file /opt/etc/.htpasswd;
uwsgi_pass unix:///tmp/uwsgi_***.sock;
include uwsgi_params;
}
location /static {
# Point this wherever the static files for your django app are stored (i.e. MEDIA_ROOT)
alias /opt/apps/****/static;
}
}
server {
listen 80 default_server;
server_name "";
location / {
rewrite ^ https://****.com$request_uri permanent;
}
}
A random stab at this, without knowing enough info yet…
Its possible that what is happening, is the first request goes through the web server and on to django. Django redirects to a new url with query string, and then the request goes back through the webserver again. At that point, I think the web server is splitting up the pattern improperly. Normally when I see this, the webserver wants to see a trailing slash on the pattern to inform it that it should treat the entire url pattern raw:
So try this maybe (adding trailing slash):
Other than this, you might need to go into more detail about your production web server.
If your production server really is performing the redirect, and not django, then you should definitely look into making sure the trailing slash is present in the rule.
Update: Based on the added nginx conf
I think your problem might be your rewrite rule for https. Its quite possibly re-appending the query string because of a single missing
?http://wiki.nginx.org/HttpRewriteModule
Try making this change in your nginx conf:
Lastly, just to address your comment about the behavior of your https redirect, I think you might want to adjust that as well. I actually do something almost exactly the same on one of my servers. But I make the ssl server default, and I don’t use a location directive in the port 80 server: