1

I have a problem with my redirections.

Basically, I get the name of the page using a page GET variable, like this: index.php?page=page1, which I want to be accessed by page1.html

Then, if there are other get variables, I just want to append them, like this: page1.html?var1=value1 points to index.php?page=page1&var1=value1

I tried the following:

RewriteRule ^([a-zA-Z]+)\.html$  index.php?page=$1  [L]
RewriteRule ^([a-zA-Z]+)\.html\?(.*)$  index.php?page=$1&$2  [L]

And I never seem to get any other get parameter than the page variable...
Thanks

1 Answer 1

2

You need to use the Query String Append flag.

Per the docs:

When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.

Update your rule like so:

RewriteRule ^([a-zA-Z]+).html$ index.php?page=$1 [L,QSA]
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.