I’m struggling with a particular rewrite rule on apache. More precise, I’m struggling to understand what’s wrong with it.
I need to rewrite urls like so:
http://www.mysite.com/section/venue_info/123/name
or
http://www.mysite.com/section/venue_info/123/
or
http://www.mysite.com/section/venue_info/123
|
V
http://www.mysite.com/section/venue_info.php?id=123
Note that section is a variable in the equation. In live site it can be one of a several values, so whatever section was supplied, I need to use that section. I’ve got this in my apache config:
DocumentRoot /var/www/site/trunk/publish
<Directory /var/www/site/publish/trunk/>
Options -Indexes +FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
RewriteEngine on
RewriteBase /
RewriteRule ^\/(\w+)\/venue_info\/(\d+)(\/.+|\/?)$ $1/venue_info.php?id=$2
</Directory>
However this doesn’t match. I’ve tried all sorts of variations, but no with no luck. What’s the right RewriteRule here? Any help is appreciated.
Ok, figured it out!
Apparently,
mod_rewritedirectives would not work inside<Directory>element. Once I placed them into<Location>block, everything worked just fine. So now my apache config looks like this:And everything works just fine.