[thelist] htaccess mod_rewrite help please!!!

Stephen Rider evolt_org at striderweb.com
Wed Oct 4 08:42:12 CDT 2006


On Oct 3, 2006, at 10:58 PM, David Kaufman wrote:

> Stephen Rider <evolt_org at striderweb.com> wrote:
>> ...in one directory /blog/ and a symbolic link,
>> /blog2/ (and /blog3/, /blog4/...) that points to the /blog/  
>> directory...
>>
>> I want to tell the [mod_rewrite] block, essentially, "If the
>> directory structure starts with /blog/, point to /blog/index.php.
>> If it starts with /blog2/ point to /blog2/index.php
>
> You need to remove their rewrite rule
> in the /blog/ dir, modify it and place it in an .htaccess file one
> directory *up*, in this case, the document root of your site.
>
> Try this, in /.htaccess
>
> RewriteEngine On
> RewriteCond %{REQUEST_URI}        ^/blog([0-9]*)/
> RewriteCond %{REQUEST_FILENAME}   !-f
> RewriteCond %{REQUEST_FILENAME}   !-d
> RewriteRule .                     /%1/index.php [L]

David (et al):

Okay, first off, "blog1" "blog2" etc. was just an example -- the  
actual blog names can be just about anything.  For initial testing, I  
tried your rewrite with just "blog" in place, like this:

> RewriteCond %{REQUEST_URI}        ^/(blog)/

No Dice.  "File not found" on anything but the top page of the blog.   
Further research suggests that the problem is that REQUEST_URI is the  
wrong variable (it appears to represent a string being passed to a  
script, rather than an actual path?).  I tried a LOT of variations  
beyond just the above, BTW.  I really think this is the right  
approach though -- I had been leaning in this direction already.  :)

The Apache mod_rewrite docs shows a list of variable names that can  
be used in RewriteCond, but doesn't define them, and I'm having a  
hard time simply finding a list of basic definitions of what these  
variables represent.
<http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteCond>

Trying to look them up individually is a huge pain because many of  
them mean different things in different contexts, and I keep getting  
sidetracked by similar variables that aren't actually available to  
mod_rewrite!  All the cryptic descriptions with no example doesn't  
help either.  ("This is the path from the root".  Server root/web  
root?  Slashes included/excluded??   Filename included/excluded???  
ARGH!!!)

NEW QUESTION:  Does anyone know where I can find a good list defining  
those variables that can be used in RewriteCond?  Preferably with  
clear examples for each?

OR, is there a good way to test what these variables are  
representing?  Can I stick them in a simple PHP file or something to  
get their values?

Back to the rewrite:
> RewriteEngine On
> RewriteCond %{REQUEST_URI}        ^/(blog)/
> RewriteCond %{REQUEST_FILENAME}   !-f
> RewriteCond %{REQUEST_FILENAME}   !-d
> RewriteRule .                     /%1/index.php [L]

For different blogs, I believe I can do something like this:
^/([bob|joe|sally])/

But... doesn't that string need something after the slash to  
represent whatever comes after?  I would think something like...

^/([bob|joe|sally])/(.*)(/.*)*   <--that last bit should be: "zero-or- 
more characters followed by zero-or-more (slash followed by zero or  
more characters)"

Thanks again
Stephen



More information about the thelist mailing list