Go Back   SitePoint Forums > Forum Index > Host Your Site > Apache Configuration
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old Dec 14, 2004, 17:18   #1
Vogelfrei
SitePoint Zealot
 
Vogelfrei's Avatar
 
Join Date: Jan 2004
Location: west of the divide
Posts: 154
mod_rewrite directories to fuseactions - [N], path-info, and infinity

I'd like to use mod_rewrite to disguise the Fusebox nested circuit model (dot notation) as nested directories. That is, if the user requests
http://www.example.com/products/skis/alpine/
I want to rewrite them to
http://www.example.com/index.php?action=products.skis.alpine

The key here is that there can be an arbitrary number of items in the dot-delimited list. (In practice, it rarely goes more than 3 deep, but I'd like this to be completely flexible.)

So, here's the problem: to address the arbitrary length of the action, I decided to try using [N] in my RewriteRule. And it almost works. But unfortunately, the path-info is getting appended to my rewritten URI, throwing it into a loop.

Here is the full text of my .htaccess file.

Code:
RewriteEngine on

RewriteCond %{REQUEST_URI}	!favicon.ico [NC]
RewriteCond %{REQUEST_URI}	!robots.txt [NC]
RewriteCond %{REQUEST_URI}	!images/ [NC]
RewriteRule ^([^/]+)/(.*)$	$1.$2 [N]

RewriteCond %{REQUEST_URI}	!index.php [NC]
RewriteRule ^([a-z0-9.]+)	index.php?action=$1&%{QUERY_STRING} [L]
The heart of the matter, of course, is the first RewriteRule with the [N].

So if I request http://www.example.com/products/skis/alpine/ , I'll see the following RewriteLog entries:
Code:
add path-info postfix: /www/products -> /www/products/skis/alpine
strip per-dir prefix: /www/products/skis/alpine -> products/skis/alpine
applying pattern '^([^/]+)/(.*)$' to uri 'products/skis/alpine'
RewriteCond: input='/products/skis/alpine' pattern='!favicon.ico' => matched
RewriteCond: input='/products/skis/alpine' pattern='!robots.txt' => matched
RewriteCond: input='/products/skis/alpine' pattern='!images/' => matched
rewrite products/skis/alpine -> products.skis/alpine
add per-dir prefix: products.skis/alpine -> /www/products.skis/alpine
Looks good so far.
Code:
add path-info postfix: /www/products.skis/alpine -> /www/products.skis/alpine/skis/alpine
Uh-oh. You can see where this is going to lead.
Code:
strip per-dir prefix: /www/products.skis/alpine/skis/alpine -> products.skis/alpine/skis/alpine
applying pattern '^([^/]+)/(.*)$' to uri 'products.skis/alpine/skis/alpine'
RewriteCond: input='/products/skis/alpine' pattern='!favicon.ico' => matched
RewriteCond: input='/products/skis/alpine' pattern='!robots.txt' => matched
RewriteCond: input='/products/skis/alpine' pattern='!images/' => matched
rewrite products.skis/alpine/skis/alpine -> products.skis.alpine/skis/alpine
The ironic part is that at this point, my action looks how I want it: "products.skis.alpine". But that pesky path-info isn't going to let us stop.
Code:
add per-dir prefix: products.skis.alpine/skis/alpine -> /www/products.skis.alpine/skis/alpine
add path-info postfix: /www/products.skis.alpine/skis/alpine -> /www/products.skis.alpine/skis/alpine/skis/alpine
strip per-dir prefix: /www/products.skis.alpine/skis/alpine/skis/alpine -> products.skis.alpine/skis/alpine/skis/alpine
applying pattern '^([^/]+)/(.*)$' to uri 'products.skis.alpine/skis/alpine/skis/alpine'
RewriteCond: input='/products/skis/alpine' pattern='!favicon.ico' => matched
RewriteCond: input='/products/skis/alpine' pattern='!robots.txt' => matched
RewriteCond: input='/products/skis/alpine' pattern='!images/' => matched
rewrite products.skis.alpine/skis/alpine/skis/alpine -> products.skis.alpine.skis/alpine/skis/alpine
add per-dir prefix: products.skis.alpine.skis/alpine/skis/alpine -> /www/products.skis.alpine.skis/alpine/skis/alpine
add path-info postfix: /www/products.skis.alpine.skis/alpine/skis/alpine -> /www/products.skis.alpine.skis/alpine/skis/alpine/skis/alpine
....
ad infinitum. (or rather, ad kill apache.)

So... Can I do something to keep that path-info from being postfixed? or am I barking up the wrong tree using the [N] flag at all?
Vogelfrei is offline   Reply With Quote
 

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 01:05.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved