Free eBooks Download - www.knowncrafts.net - Payday Loan - The eBay Song - Car Insurance

PDA

View Full Version : Mod Rewrite Question


T0PS3O
Sep 12th 2004, 1:37 pm
I've spent all afternoon and evening reading the literature on apache's rewrite module. Most tutorials are either too basic and most serious papers are too complex IMHO.

Question: Is the following possible at all?

For a new project I'd like to use the following URL structure:

w ww.domain.com/script/category/grandparent/parent/child (not sure on trailing slash here at the end)

and have it reconverted to:

w ww.domain.com/script.php?cat=category&grp=grandparent&par=parent&chi=child

What I've gathered over the last few hours is that it is quite easy yo have it like:

w ww.domain.com/script/cat/category/grp/grandparent/par/parent/chi/child

but that is not how I want it.
Is it possible at all to have it like I want where the rewrite rules basically says: the first dir calls the appropriate php script, the 2nd directory name will be the value of the variable $cat etc. etc.

Please let me know whether I should continue my research or just stop wanting it my way and rethink my strategy.

arestia
Sep 12th 2004, 3:27 pm
I've spent all afternoon and evening reading the literature on apache's rewrite module. Most tutorials are either too basic and most serious papers are too complex IMHO.

Question: Is the following possible at all?

For a new project I'd like to use the following URL structure:

w ww.domain.com/script/category/grandparent/parent/child (not sure on trailing slash here at the end)

and have it reconverted to:

w ww.domain.com/script.php?cat=category&grp=grandparent&par=parent&chi=child

What I've gathered over the last few hours is that it is quite easy yo have it like:

w ww.domain.com/script/cat/category/grp/grandparent/par/parent/chi/child

but that is not how I want it.
Is it possible at all to have it like I want where the rewrite rules basically says: the first dir calls the appropriate php script, the 2nd directory name will be the value of the variable $cat etc. etc.

Please let me know whether I should continue my research or just stop wanting it my way and rethink my strategy.
i too had a hard time when trying to accomplish this on one of my clients sites. we had a structure simular to yours.


Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/script/(.*)/(.*)/(.*)/(.*)/
RewriteRule ^(.*)/ /script\.php?cat=%1&grp=%2&par=%3&chi=%4 [L]

T0PS3O
Sep 13th 2004, 5:20 am
Excellent, I'll try it out!

Would it allow for empty child or parent variables?

Like if I want to display all links to available child variables when this page is requested?

w ww.domain.com/script/category/grandparent/parent/

Thanks very much though.