Pierre
Pierre

Reputation: 13

.htaccess rewriting and GET parameters

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

Upvotes: 1

Views: 41

Answers (1)

Jason McCreary
Jason McCreary

Reputation: 72971

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]

Upvotes: 2

Related Questions