Reputation: 818
I don't have problem setting a GET variable when there is no regular expression in the rewrite rule. For example the following works as expected, when I execute sample.html?test=OK
the test
variable in sample.php
is set as OK
.
RewriteRule ^sample.html sample.php [NC]
The problem starts when there is regular expression in the rewrite rule. For example the following is not working as the above one.
RewriteRule ^sample-(.*).html sample.php?one=$1 [NC]
I want to execute URL like sample-123.html?test=OK
while I have both one
and test
get their values in sample.php
.
I've read multiple questions in here but non were answering this type of problem. I saw different answers suggesting using RewriteCond
. I tried them but with no luck, as I'm not expert in .htaccess at all.
Many thanks in advance.
Upvotes: 1
Views: 300
Reputation: 786289
You will need QSA
flag here:
RewriteRule ^sample-(.+)\.html$ sample.php?one=$1 [L,QSA,NC]
QSA
(Query String Append) flag preserves existing query parameters while adding a new one.Upvotes: 2