Matt
Matt

Reputation: 7192

Help with mod_rewrite

I'm trying to get mod_rewrite working with the following URLs:

/events.php?view=details&id=$var
/events.php?view=edit&id=$var

Obviously my goal is to have /events/details/$var and /events/edit/$var be my actual URL's, and $var is an unique ID.

My .htaccess file

RewriteEngine On

# redirect 301 /events.php http://www.google.com
# If the rule above is active, it does redirect to google.com, 
# so .htaccess is working

RewriteRule ^events/([^/]*)/([^/]*)\$ /events.php?view=$1&id=$2 [L]

Currently when I go to /events/details/$var it's displaying /events.php but not picking up the variables being passed in.

Any help would be appreciated!

Update: I removed the .php mentioned by OverZealous. /events/details/$var still displays /events.

// From events.php
echo $_REQUEST['view']; //returns nothing

Update2: I enabled the mod_rewrite log (level 5) and got the following output: (I stripped out the IP, date, my domain details etc)

[sid#7fc6d76f5608][rid#7fc6d79ad908/subreq] (3) [perdir /var/www/webroot/] add path info postfix: /var/www/webroot/events.php -> /var/www/webroot/events.php/details/35
[sid#7fc6d76f5608][rid#7fc6d79ad908/subreq] (3) [perdir /var/www/webroot/] strip per-dir prefix: /var/www/webroot/events.php/details/35 -> events.php/details/35
[sid#7fc6d76f5608][rid#7fc6d79ad908/subreq] (3) [perdir /var/www/webroot/] applying pattern '^events/([^/]*)/([^/]*)$' to uri 'events.php/details/35'
[sid#7fc6d76f5608][rid#7fc6d79ad908/subreq] (1) [perdir /var/www/webroot/] pass through /var/www/webroot/events.php

[sid#7fc6d76f5608][rid#7fc6d79a88e8/initial] (3) [perdir /var/www/webroot/] add path info postfix: /var/www/webroot/events.php -> /var/www/webroot/events.php/details/35
[sid#7fc6d76f5608][rid#7fc6d79a88e8/initial] (3) [perdir /var/www/webroot/] strip per-dir prefix: /var/www/webroot/events.php/details/35 -> events.php/details/35
[sid#7fc6d76f5608][rid#7fc6d79a88e8/initial] (3) [perdir /var/www/webroot/] applying pattern '^events/([^/]*)/([^/]*)$' to uri 'events.php/details/35'
[sid#7fc6d76f5608][rid#7fc6d79a88e8/initial] (1) [perdir /var/www/webroot/] pass through /var/www/webroot/events.php

[sid#7fc6d76f5608][rid#7fc6d7a597c8/subreq] (3) [perdir /var/www/webroot/] add path info postfix: /var/www/webroot/details -> /var/www/webroot/details/35
[sid#7fc6d76f5608][rid#7fc6d7a597c8/subreq] (3) [perdir /var/www/webroot/] strip per-dir prefix: /var/www/webroot/details/35 -> details/35
[sid#7fc6d76f5608][rid#7fc6d7a597c8/subreq] (3) [perdir /var/www/webroot/] applying pattern '^events/([^/]*)/([^/]*)$' to uri 'details/35'
[sid#7fc6d76f5608][rid#7fc6d7a597c8/subreq] (1) [perdir /var/www/webroot/] pass through /var/www/webroot/details

Upvotes: 0

Views: 289

Answers (1)

OverZealous
OverZealous

Reputation: 39560

Why do you have \.php at the end? Do you want the URLs to be /events/details/123.php? Because that's not what your example is.

I think you want your rewrite rule to look like:

RewriteEngine On
RewriteRule ^events/([^/]*)/([^/]*)$ /events.php?view=$1&id=$2 [L]

Upvotes: 2

Related Questions