Skip to content

Apache mod_rewrite query string matches from RewriteCond not available in RewriteRule substitution when QSD flag used  #10768

@mikevh

Description

@mikevh

Using the rewrite rule below, read in from the mod_rewrites.txt. The resulting redirect does not have the report id value as expected at the end of the url. The %1 should have the value matched from the backreference to the RewriteCond line. This rule works as I expect on Apache

To Reproduce

  1. Using ASP.NET Core 2.2

  2. Add mod_rewrites.txt with this rewrite rule in it
    RewriteCond %{REQUEST_URI} /home
    RewriteCond %{QUERY_STRING} report_id=(.+)
    RewriteRule (.*) http://localhost:64782/home/report/%1 [R=301,L,QSD]

  3. Add this call in Startup.cs

using (var sr = File.OpenText("mod_rewrites.txt")) {
    var rwo = new RewriteOptions().AddApacheModRewrite(sr);
    app.UseRewriter(rwo);
}
  1. Add HomeController action
[HttpGet("/home/report/{id}")]
        public IActionResult Report(int id)
        {
            return Content("rewritten id = " + id);
        }
  1. Run and navigate to http://localhost:64782/home?report_id=123

Expected behavior

Rewritten URL is http://localhost:64782/home/report/123

Actual behavior

Rewritten URL is http://localhost:64782/home/report/

Additional context

This rewrite rule works as expected in Apache

Issue previously submitted as doc bug here

Metadata

Metadata

Assignees

Labels

acceptedThis issue has completed "acceptance" testing (including accessibility)area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewares

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions