coop coop - 1 year ago 77
PHP Question

$_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.



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) "" }

Answer Source

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]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download