Rewrite as one page, variable length parameters

New to mod_rewrite? This is a good place to start.

Rewrite as one page, variable length parameters

Postby harrykrishna » Wed Aug 26, 2009 11:25 am

Hi guys,

I am trying to make a rule that first matches one page in the path and then uses the rest of the path after that as parameters of variable length/quantity for the requested page.

My rule is
RewriteRule ^([^/\.]+)/?([.]?)/?$ index.php?page=$1&params=$2

i want this rule to work on paths such as:
site.com/articles
site.com/articles/well-drilling
site.com/articles/2009/08/12/know-your-milkman

so everything after "articles" would be captured by $2 and then i would parse the params variable on the page it is directed to.

thanks for any help
harrykrishna
 
Posts: 1
Joined: Wed Aug 26, 2009 11:17 am

Postby richardk » Sat Aug 29, 2009 2:18 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)(/(.*))?$ /index.php?page=$1&params=$3 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 32 guests

cron