user892134
user892134

Reputation: 3214

isset and $_GET with url, fix mod_rewrite

I have done mod_rewrite for category.php.

RewriteRule ^category/([A-Za-z0-9-]+)(&type=[A-Za-z0-9-]+)?(&r=[A-Za-z0-9-]+)?(&g=[A-Za-z0-9-]+)?(&v=[A-Za-z0-9-]+)?(&page=[A-Za-z0-9-]+)?/?$ /category.php?c=$1&type=$2&r=$3&g=$4&v=$5&page=$6 [L]

With this url in the browser;

http://localhost/category/general

I test if v exists

if(isset($_GET['v'])) {
echo "yes";
}

yes is displayed but it isn't in the url? If the url was this..

http://localhost/category/general&v=1

then yes should be displayed. How do i fix this?

Upvotes: 0

Views: 198

Answers (1)

Samuel Cook
Samuel Cook

Reputation: 16828

You are always calling category.php with c=$1&type=$2&r=$3&g=$4&v=$5&page=$6 as the query string. Using isset() is inefficient as it will always be set. I would use empty() instead.

if(!empty($_GET['v'])) {
    echo "yes";
}

Upvotes: 1

Related Questions