skip to Main Content

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

2

Answers


  1. Try this code:

    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&$3 [L]
    
    Login or Signup to reply.
  2. 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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search