I'm trying to make my wampserver reach my querystring vars under friendly urls (htaccess changes).
All I can get is a notice telling me that they don't exist...
What is wrong?
My rewrite_modulo is ON. By default, wampserver calls products.php if I type "http://localhost/product".
But I can't access my url vars!
My folder is "project" (inside www dir)
-> www/project
Here is what I get:
My HTACCESS:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /project/
RewriteRule ^products/([a-z0-9-]+)/([0-9]+)/?$ /products.php?id=$2&name=$1 [NC]
</IfModule>
And my "products.php" is like this:
<?php
$id = $_GET['id'];
$name = $_GET['name'];
?>
But when I run this page (http://localhost/products/myID/myName) I get this notices:
- Notice: Undefined index: id in C:\wamp64\www\project\products.php on line 5
- Notice: Undefined index: name in C:\wamp64\www\project\products.php on line 6
Add the QSA (query string append) flag to your rule, like:
RewriteRule ^products/([a-z0-9-]+)/([0-9]+)/?$ /products.php?id=$2&name=$1 [NC,QSA]
Important: no spaces between the comma-delimited flags.
You need to turn MultiViews
option off:
Options -MultiViews
RewriteEngine on
RewriteBase /project/
RewriteRule ^products/([a-z0-9-]+)/([0-9]+)/?$ /products.php?id=$2&name=$1 [NC,L,QSA]
Option MultiViews
(see http://httpd.apache.org/docs/2.4/content-negotiation.html) is used by Apache's content negotiation module
that runs before mod_rewrite
and makes Apache server match extensions of files. So if /file
is the URL then Apache will serve /file.html
.