Why is this RewriteRule altering QUERY_STRING, but leaving REQUEST_URI untouched?

Viewed 619

I have a copy of Concrete5, a PHP-based CMS, running on example.com.

Concrete5 comes with the following basic instructions for pretty URLs (redirecting all URLs to a central index.php)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/c5.7
RewriteRule ^.*$ c5.7/$0 [L]    # Concrete5 is running in the c5.7/ subdirectory
</IfModule>

Pretty straightforward.

Now I have a certain set of URLs that take the form

 /product/{productname}

that I need to forward to the Concrete5 (virtual) URL

/products/details?name={productname}

That URL is set up and works as expected when I enter it manually in the browser.

So I added a line to the htaccess file and it now looks like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# New rule for products
RewriteCond %{REQUEST_URI} ^/product/
RewriteRule ^product/(.+)$ /products/details?name=$1 [QSA]

RewriteCond %{REQUEST_URI} !^/c5.7
RewriteRule ^.*$ c5.7/$0 [L]

</IfModule>

I can confirm the RewriteRule gets triggered when I choose a random, external URL as the redirection target.

But whenever it is an internal redirect like above, what happens is, I get a 404 inside Concrete5. When I inspect what was passed to it, I see:

 REQUEST_URI:  /product/my-random-product
 QUERY_STRING: name=my-random-product

So it appears that the rule is triggered and does some rewriting, but REQUEST_URI remains unchanged!

Why?

Is it because PHP 7.1 is running via CGI?

I have tried a zillion variations and all the flags in the book, with little success.

3 Answers
Related