LazyD Posted May 3, 2007 Share Posted May 3, 2007 I originally posted this at Digital Point forums and got one solution, yet its still not exactly what I need... Im simply using htaccess to rewrite URLs and using PHP to $_GET the variables... Problem is, when I echo out the $_GET variable its echoing the word "index" instead of the word in the URL My htaccess: RewriteEngine on RewriteRule ^(.*)/(.*)\.php$ index.php?Category=$1&SubCat=$2 [L] RewriteRule ^(.*)\.php$ index.php?Category=$1 [L] My PHP file: $CategoryGet = $_GET['Category']; $SubCatGet = $_GET['SubCat']; echo $CategoryGet; Now, if I go to http://mydomain.com/Jerseys.php the echo outputs "index" Now, if i go http://mydomain.com/Jerseys/Youth.php the echo again, outputs "index" This also effects it even when I use index.php?Categoy=Jerseys When I remove the lines from the htaccess, it magically starts working again.... What the hell is going on.. INTERESTING UPDATE ------ When I change the following in my htaccess it works... RewriteRule ^(.*)\.html$ index.php?Category=$1 [L] Changing the destination URL from PHP to HTML fixes it.... However, I want them to .php... Another update.... I tried changing it to the following: RewriteRule ^(.*)\.php4$ index.php?Category=$1 [L] That works as well, for whatever reason, it seems that this thing is retarded and cant handle a plain .php The solution that was given to me was as follows: The request for index.php?Category=originalcat will in turn be rewritten again to index.php?Category=index You can either put the rewrite code into your httpd.conf and the [L] flag will stop processing after the first rewrite (as .htaccess are only interpreted perdir, Apache has to make another request for the new location in case any more rewrites apply). Or add in a RewriteCond to check your filename against already being the index script. I.e. RewriteCond %{SCRIPT_FILENAME} !index\.php$ RewriteRule ^(.*)/(.*)\.php$ index.php?Category=$1&SubCat=$2 [L] RewriteCond %{SCRIPT_FILENAME} !index\.php$ RewriteRule ^(.*)\.php$ index.php?Category=$1 [L] The problem is, I have those product pages that are being rewritten have links to the products, the link is to cart.php, the problem is, when you click the link to the product, it simply redirects you back to the index.php Right now im making them rewrite to .html, but I would like them to be .php like the rest of the pages on my site How can I solve this issue? Link to comment https://forums.phpfreaks.com/topic/49873-php-htaccess-_get-issue/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.