'htaccess rewrite fake directories to GET parameters in PHP

My htaccess file is

RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^news/(.*)$ index.php?news=$1 [QSA]

so if I goto https://example.com/news/2022-04-01 it should really goto https://example.com?news=2022-04-01 and according to htaccess.madewithlove.com that it what it evaluates to. However, the PHP (index.php in this case), still sees it as /news/2022-04-01 and the $_GET array is empty. Am I missing something really obvious since the whole point of the rewrite is to change it to a GET parameter before it hits my PHP file. Putting this at the start of my PHP file

<?php
echo "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]<br/>";
print_r($_GET);
die();

shows array() if I pass it as a directory (which shows it does just goto index.php) but array('news'=>'2022-04-01') if I do it as 'normal' parameter passing. So, can it be done in PHP (or JQuery/Javascript).. And if it can be done, please don't hardcode 'news', there are 8 different possibilities being passed so I need a generic routine. Many thanks Adrian



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source