Reputation: 23
I've been wrestling with a mod_rewrite rule that doesn't seem to be working. Briefly, I want the following URL: www.servername.com/showtest/1 to redirect to: www.servername.com/showtest.php?id=1
I thought the following in my .htaccess should get the redirect working:
RewriteEngine On
RewriteRule ^showevent/(\w+)/?$ showevent.php?id=$1 [L,R,QSA]
However, it doesn't seem to work and I the $_GET and $_REQUEST variables in PHP are both empty, as far as I can see.
I have tried to do some debugging, including a variety of different Regexs. I also turned on mod_rewrite logging to have a look around (I'm working on a local server). These are the relevant lines:
127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76d0058/subreq] (1) [perdir /var/www/1277/] pass through /var/www/1277/showevent.php
127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76db058/initial] (3) [perdir /var/www/1277/] add path info postfix: /var/www/1277/showevent.php -> /var/www/1277/showevent.php/1
127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76db058/initial] (3) [perdir /var/www/1277/] strip per-dir prefix: /var/www/1277/showevent.php/1 -> showevent.php/1
127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76db058/initial] (3) [perdir /var/www/1277/] applying pattern '^showevent/(\w+)/?$' to uri 'showevent.php/1'
127.0.0.1 - - [01/Nov/2011:12:25:55 +0100] [127.0.0.1/sid#b7843948][rid#b76db058/initial] (3) [perdir /var/www/1277/] add path info postfix: /var/www/1277/showevent.php -> /var/www/1277/showevent.php/1
It seems that, instead of re-writing to showevents.php?id=1, it is rewriting to showevent.php/1
I would welcome any help you could give.
Upvotes: 2
Views: 82
Reputation: 1995
It does happen, because of the Flags you use in your rewrite rule. You want to change
[L,R,QSA] to just "[L]"
See http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriteflags for reference.
Upvotes: 1