title: mod_rewrite + django causing incorrect redirect URLs post login
body: <p>I have a Django project with an app named &quot;Surveys&quot; - it is desired that URLs such as <a href="http://example.com/Surveys/ViewInspection/1" rel="nofollow noreferrer">http://example.com/Surveys/ViewInspection/1</a> are accessible via <a href="http://example.com/Inspections/ViewInspection/1" rel="nofollow noreferrer">http://example.com/Inspections/ViewInspection/1</a>.</p>
  <p>Using Apache 2.4 and mod_rewrite, I have the following set of rules in place to allow this:</p>
  <pre><code>RewriteEngine On
  RewriteRule ^/Inspections(.+)$ /Surveys$1 [PT]
  </code></pre>
  <p>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.</p>
  <p>At this point, the user is bounced to the login screen with parameters:</p>
  <pre><code>/Auth/Login?next=/Ins/Surveys/ViewInspection/1
  </code></pre>
  <p>After a bit of digging, &quot;/Ins/Surveys/ViewInspection/1&quot; 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 &quot;Inspections&quot; the Ins part decreases until disappearing, when it all works fine.</p>
  <p>mod_rewrite logs look correct in this instance:</p>
  <pre><code>[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' -&gt; '/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
  </code></pre>
  <p>Any idea what I'm doing wrong here to cause request.path to be wrong and foul up the redirects after login?</p>
  <p>If I shorten the &quot;Inspections&quot; part in the re-write rule, it correspondingly shortens the &quot;Ins&quot; part of the incorrect request.path - so a short (&lt;8 character) string in place causes everything to work perfectly. I just can't see where this is taking place.</p>