'.htaccess rewrite rule from end of path

I need to rewrite the rule for my url according to this pattern:

Starting url :

https://example.com/path/&param1=1&param2=2

Destination url:

https://example.com/file.php?param1=1&param2=2

I therefore need to get everything that comes after the & character.

I know it's poorly formed the starting url and that the ? would be needed, but unfortunately I have this pattern to follow. I tried this but I can't get the & character.

RewriteRule ^path([&])$ file.php?$1 [L]

Do you have any ideas?



Solution 1:[1]

With your shown samples, attempts please try following htaccess rules file. This does internal rewrite to file.php and sends query string as param1=1&param2=2 in backend.

Also make sure your file.php and .htaccess rules file are in same path. Make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/[^&]*&(\S+) [NC]
RewriteRule ^ file.php?%1 [QSA,L]

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 RavinderSingh13