views:

16

answers:

2

hello there.

building a site which has content for each section.

urls range from;
/work/
/work/print/
/work/print/folders etc.

however, at any point a user can click on an article so;
/work/article/1066
/work/print/article/1066
/work/print/folders/article/1066

using .htaccess i need to detect when there is 'article' in the url and set some different variables.

RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ 
sets  index.php?level1=$1&level2=$2&level3=$3&level4=$4

but if 'article/([0-9-]+)' is in the url, say /work/print/article/1066 return index.php?level1=$1&level2=$2&articleID=1066

basically the amount of levels will always be different but i'd like to return those as needed. another example would /work/print/folder/archive/article/1066 return

index.php?level1=$1&level2=$2&level3=$3&level4=$4&articleID=1066

any help appreciated! Dan

A: 

A simple solution will be to do the level detection in your php script.

RewriteRule ^(.+)/article/(\d+)$ index.php?levelsUri=$1&articleID=$2

You can then parse the "levelsUri" request value and detect the levels in your php script.

Ramesh Tabarna
A: 

in the end i just did it manually! (though would prefer a more expansive solutions)

# MENU ###

RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$  index.php?level1=$1&level2=$2&level3=$3 [L]

RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$  index.php?level1=$1&level2=$2 [L]

RewriteRule ^([a-zA-Z0-9\-]+)/$  index.php?level1=$1 [L]


###  WITH ARTICLE  ###


RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/article/([0-9\-]+)/([a-zA-Z0-9\-]+)$$  index.php?level1=$1&level2=$2&level3=$3&articleID=$4 [L]

RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/article/([0-9\-]+)/([a-zA-Z0-9\-]+)$$  index.php?level1=$1&level2=$2&articleID=$3 [L]

RewriteRule ^([a-zA-Z0-9\-]+)/article/([0-9\-]+)/([a-zA-Z0-9\-]+)$  index.php?level1=$1&articleID=$2 [L]


RewriteRule ^$  index.php?level1=home [L]
daniel Crabbe