match 'article' in url RewriteRule

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

Answers


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.


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]

Need Your Help

Segmentation fault in strcmp() on C

c pointers scanf

My program to compare strings fails with Segmentation Fault after the second input:

Need SQL Server Stored Procedure for This Query

sql-server stored-procedures datagrid asp.net

I have a ASPX.NET DataGrid and im trying to USE a select LIKE 'X'% from a table that has 1 field called location. im trying to display the locations that start with a certain letter (example wxxx,a...