Skip to main content
edited tags
Link
MrWhite
  • 46.4k
  • 9
  • 67
  • 90
Source Link
Nashie
  • 331
  • 2
  • 12

PHP GET after htaccsess rewrite

I am trying to get the variable from my url but having problems.

the default URL is http://localhost/category.php?category_slug=gaming

With my htaccsess file

RewriteRule ^category/([\w\d-]+)$ /category.php?category_slug=$1 [L] RewriteCond %{QUERY_STRING} category_slug=([\w\d-]+) RewriteRule ^category$ %1 [R,L] 

I get my desired URL http://localhost/category/gaming

but now I am needing to get the page variable from the url http://localhost/category/gaming?page=2

in category.php i have $page=$_GET['page'];

but when I echo it out i get Warning: Undefined array key "page" in F:\Server\htdocs\category.php on line 5

The closest i can get is with the following code

RewriteRule ^category/([\w\d-]+)$ /category.php?category_slug=$1&page=$2 [L] RewriteCond %{QUERY_STRING} category_slug=([\w\d-]+) RewriteRule ^category$ %1 [R,L] 

I get no errors but the data isnt showing

The desired URL would be either http://localhost/category/gaming?page=2 or http://localhost/category/gaming/page2/

im pretty sure my lack of knowledge of editing my htaccsess file is to blame. and need someone to point me in the right direction please