View Single Post

  #2 (permalink)  
Old 08-19-2006
Rik
 
Posts: n/a
Default Re: mod_rewrite and url depth

Peanut Butter & Jelly wrote:
> Hi,
>
> I tried to use many variations of RewriteRule but I couldn't get it

to
> work as I'd like to. The thing is I need to use up to 3 variables in
> url which looks like:
> http://www.domain.com/index.php?cat=a&sub=b&item=c
>
> I'd like to make it work with urls entered as follows:
> 1)
> http://www.domain.com/a/b/c.html
> pointing to: http://www.domain.com/index.php?cat=a&sub=b&item=c
>
> 2)
> http://www.domain.com/a/b/
> http://www.domain.com/a/b
> http://www.domain.com/a/b.html
> pointing to: http://www.domain.com/index.php?cat=a&sub=b
>
> 3)
> http://www.domain.com/a
> http://www.domain.com/a/
> http://www.domain.com/a.html
> pointing to: http://www.domain.com/index.php?cat=a
>
> Is it possible to make it work? And if, I will appreciate any hint

how
> to solve this problem.


Well, if you can accept 'emtpy' GET variables in your script (ie, in
the last case indec.php?cat=a&sub=&item= is no trouble, which is the
way I usually write:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/?([^/]*)?/?([^/]*)?/?(\.html)?$
index.php?cat=$1&sub=$2&item=$3

--
Grtz,

Rik Wasmus