1

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.

1

1 Answer 1

2

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.