Here’s what I’m trying to achieve:
Before:
After:
The URL must specifically have that query at the end. I wanted to avoid using these static methods:
http://www.example.com/page/about/pg/5/
or
http://www.example.com/about/5/
Here’s what I have so far:
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z-]+)\.html\?pg\=([0-9]+)$ index.php?page=$1&pg=$2 [L]
When I var_dump($_GET); only the ‘page’ parameter was visible.
I wanted the result as if I type in the address bar, http://www.example.com/about.html?pg=5 would mean the same as typing http://www.example.com/index.php?page=about&pg=5. Instead of using .php I wanted for it show as .html. the parameter ‘pg’ is for me to use as hyperlink for various pages. I wanted to strip out the ‘index.php’ and make it as ‘about.html’, and the rest of the query follows.
For an example, this page will be used for an article. There will be a section for comments in that article. I wanted to control the pages of the comments with the parameter ‘pg’.
If I understand you right, you want to rewrite
about.html?...toindex.php?page=about&.... If so, there’s a simple solution: just use the[QSA]flag.More generally, you can use a
RewriteCondto match text in the query string. As the documentation says:For example, another way to achieve the same effect without the
[QSA]flag would be:Or, if you want to go the other way (as I first read your question):
(Edit: Removed misplaced question marks from
RewriteConds per comments.)