mod_rewrite + django causing incorrect redirect URLs post login
I have a Django project with an app named "Survey" - it is desired that URLs such as http://example.com/Surveys/ViewInspection/1 are accessible via http://example.com/Inspections/ViewInspection/1.
Using Apache 2.4 and mod_rewrite, I have the following set of rules in place to allow this:
RewriteEngine On
RewriteRule ^/Inspections(.+)$ /Surveys$1 [PT]
and all appears to work fine, except where a non-authenticated user attempts to access the above URL (the view for which has the @login_required decorator.
At this point, the user is bounced to the login screen with parameters:
/Auth/Login?next=/Ins/Surveys/ViewInspection/1
After a bit of digging, "/Ins/Surveys/ViewInspection/1" is the value for request.path, whereas request.path_info is correctly set as /Surveys/ViewInspection/1 - the Auth code is taking .path and getting it wrong. If I use a shorter string than "Inspections" the Ins part decreases until disappearing, when it all works fine.
mod_rewrite logs look correct in this instance:
[Tue Feb 23 23:52:49.617840 2021] [rewrite:trace2] [pid 2760:tid 140156097316608] mod_rewrite.c(483): [client 213.18.147.204:4054] 213.18.147.204 - - [hostname/sid#7f78a4651338][rid#7f78a53910a0/initial] init rewrite engine with requested uri /Inspections/ViewInspection/2
[Tue Feb 23 23:52:49.617906 2021] [rewrite:trace3] [pid 2760:tid 140156097316608] mod_rewrite.c(483): [client 213.18.147.204:4054] 213.18.147.204 - - [hostname/sid#7f78a4651338][rid#7f78a53910a0/initial] applying pattern '^/Inspections(.+)$' to uri '/Inspections/ViewInspection/2'
[Tue Feb 23 23:52:49.617940 2021] [rewrite:trace2] [pid 2760:tid 140156097316608] mod_rewrite.c(483): [client 213.18.147.204:4054] 213.18.147.204 - - [hostname/sid#7f78a4651338][rid#7f78a53910a0/initial] rewrite '/Inspections/ViewInspection/2' -> '/Surveys/ViewInspection/2'
[Tue Feb 23 23:52:49.617956 2021] [rewrite:trace2] [pid 2760:tid 140156097316608] mod_rewrite.c(483): [client 213.18.147.204:4054] 213.18.147.204 - - [hostname/sid#7f78a4651338][rid#7f78a53910a0/initial] forcing '/Surveys/ViewInspection/2' to get passed through to next API URI-to-filename handler
[Tue Feb 23 23:52:49.618103 2021] [rewrite:trace2] [pid 2760:tid 140156097316608] mod_rewrite.c(483): [client 213.18.147.204:4054] 213.18.147.204 - - [hostname/sid#7f78a4651338][rid#7f78a54060a0/subreq] init rewrite engine with requested uri /Surveys/ViewInspection/2
[Tue Feb 23 23:52:49.618119 2021] [rewrite:trace3] [pid 2760:tid 140156097316608] mod_rewrite.c(483): [client 213.18.147.204:4054] 213.18.147.204 - - [hostname/sid#7f78a4651338][rid#7f78a54060a0/subreq] applying pattern '^/Inspections(.+)$' to uri '/Surveys/ViewInspection/2'
[Tue Feb 23 23:52:49.618131 2021] [rewrite:trace1] [pid 2760:tid 140156097316608] mod_rewrite.c(483): [client 213.18.147.204:4054] 213.18.147.204 - - [hostname/sid#7f78a4651338][rid#7f78a54060a0/subreq] pass through /Surveys/ViewInspection/2
Any idea what I'm doing wrong here to cause request.path to be wrong and foul up the redirects after login?
from Recent Questions - Stack Overflow https://ift.tt/3qPzJWu
https://ift.tt/eA8V8J
Comments
Post a Comment