Ad

Htaccess Rewrite Rule Seo Friendly Url With Query String

- 1 answer

I want SEO friendly urls with query string using .htaccess and get values in php $_GET variable

http://localhost/blog/categoryslug/postslug/?rf=1234&key=ad2312

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+?)/?$ /blog/detail.php?cat_slug=$1&slug=$2 [L]

but on print_r, I get only 2 keys:

print_r($_GET); exit;

Array
(
    [cat_slug] => categoryslug
    [slug] => postslug
)

while, I need all the keys and values with in query string like this:

 Array
 (
    [cat_slug] => categoryslug
    [slug] => postslug
    [rf] => 1234
    [key] => ad2312
 )

Please help me out to resolve this

TIA

Ad

Answer

Try with below, I added QSA flag to append the original incoming query to your request.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([0-9a-zA-Z-]+)/([0-9a-zA-Z-]+?)/?$ /blog/detail.php?cat_slug=$1&slug=$2 [L,QSA]
Ad
source: stackoverflow.com
Ad