Problem with "mod_rewrite"

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Problem with "mod_rewrite"

Postby JackAubrey » 25. September 2014 11:02

Hi to all, I'm new and I hope you'll apologise my horrendous English.
Since few months, I'm started to study and work with php.
I have a problem with mod-rewrite.
I'm following an exercise of Symfony and it explain that i can use mod-rewrite to convert:
Code: Select all
<a href="/show?id=1.....
in
Code: Select all
"index.php/show?id=1"
(ok this what my php front controller recive in URI)

I enabled mod-rewrite and used this rule (ok I admit, I obtained it with empiric attempts):
Code: Select all
RewriteRule ^show$ index.php/show?id=$1 [L]


My front controller (index.php) receive correct URI, "id" parameter is present in $_GET.... but empty.
If i comment RewriteRule and change
Code: Select all
"<a href="/show?id=1"
with
Code: Select all
"<a href="index.php/show?id=1"
, "id" parameter appear in $_GET and is valorized.

I'm using XAMP 1.8.2 under Windows 7.
Here the part of my httpd.conf concern mod-rewrite:
Code: Select all
LoadModule rewrite_module modules/mod_rewrite.so

#
# DocumentRoot:
#
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
    Options Indexes FollowSymLinks Includes ExecCGI
   AllowOverride All
   Require all granted
</Directory>


Here my VirtualHost in httpd-vhosts.conf
Code: Select all
<VirtualHost *:80>
   DocumentRoot C:/xampp/htdocs/PHPMVC3
   ServerName phpmvc3
   <Directory C:/xampp/htdocs/PHPMVC3>
      AllowOverride All
   </Directory>
</VirtualHost>


This is my .httaccess
Code: Select all
RewriteEngine On
# RewriteRule ^show$ index.php/show?id=$1 [L]


Where i mistake?
Thanks to all
JackAubrey
 
Posts: 2
Joined: 25. September 2014 10:51
Operating System: Windows 7

Re: Problem with "mod_rewrite"

Postby Nobbie » 25. September 2014 12:12

JackAubrey wrote:I enabled mod-rewrite and used this rule (ok I admit, I obtained it with empiric attempts):
Code: Select all
RewriteRule ^show$ index.php/show?id=$1 [L]



This is wrong, you assigned "$1" to id (what is a variable of RewriteRule, but empty in this context), instead you should simply assign "1":

Code: Select all
RewriteRule ^show$ index.php/show?id=1 [L]


And finally, in this special case, where you want to copy the original query string to the resulting URI, you dont to specify the query string, because this is the default behaviour of Rewrite, to copy the incoming query string to the resulting URI.

Code: Select all
RewriteRule ^show$ index.php/show [L]


This RewriteRule should already work for you.
Nobbie
 
Posts: 8770
Joined: 09. March 2008 13:04

Re: Problem with "mod_rewrite"

Postby JackAubrey » 25. September 2014 12:35

Great.... Thanks a lot!
Now it works! Thank you so much for giving me the error explained.
JackAubrey
 
Posts: 2
Joined: 25. September 2014 10:51
Operating System: Windows 7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 66 guests