Apache RewriteRule: it is possible to 'detect' the first and second parameter?
Posted
by DaNieL
on Stack Overflow
See other posts from Stack Overflow
or by DaNieL
Published on 2010-03-25T10:04:08Z
Indexed on
2010/03/25
10:13 UTC
Read the original article
Hit count: 506
Im really really a newbie in regexp and i cant figure out how to do that.
My goal is to have the RewriteRule to 'slice' the request url in 3 parts:
example.com/foo
#should return: index.php?a=foo&b=&c=
example.com/foo/bar
#should return: index.php?a=foo&b=bar&c=
example.com/foo/bar/baz
#should return: index.php?a=foo&b=bar&c=baz
example.com/foo/bar/baz/bee
#should return: index.php?a=foo&b=bar&c=baz/bee
example.com/foo/bar/baz/bee/apple
#should return: index.php?a=foo&b=bar&c=baz/bee/apple
example.com/foo/bar/baz/bee/apple/and/whatever/else/no/limit/in/those/extra/parameters
#should return: index.php?a=foo&b=bar&c=baz/bee/apple/and/whatever/else/no/limit/in/those/extra/parameters
In short, the first parameter in the url (foo) should be given to a, the second (bar) to b, and the rest of the string in c
I wroted this one
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(([a-z0-9/]))?(([a-z0-9/]+))?(([a-z0-9]+))(.*)$ index.php?a=$1&b=$2&c=$3 [L,QSA]
</IfModule>
but obviously doesnt work, and i dont even know if what i want is possible.
Any suggestion?
© Stack Overflow or respective owner