coop
coop

Reputation: 9

$_GET empty when using .htaccess rewrite rule

I am trying to get the var after the page name (test2), but it is empty in php.

url: https://example.com/test2/34

.htaccess:

Options +FollowSymlinks
RewriteEngine on

DirectoryIndex index.php

RewriteRule ^test2 index.php?page=test2&id=$1 [QSA]

php $_GET vardump

array(2) { ["page"]=> string(5) "test2" ["id"]=> string(0) "" }

Upvotes: 1

Views: 581

Answers (1)

anubhava
anubhava

Reputation: 785128

It is because you are not matching and capturing value after test2/.

You can use:

DirectoryIndex index.php
Options +FollowSymlinks

RewriteEngine on    

RewriteRule ^test2/(.*)$ index.php?page=test2&id=$1 [QSA,L,NC]

Upvotes: 2

Related Questions