views:

23

answers:

1
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)$ index.php?p=$1&l=$2
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ index.php?p=$1&l=$2

this works fine if I do site.com/param_one/param_two/, but returns a 404 when I omit param_two. I'm a newbie to routing requests with htaccess, is there a simple quick fix?

+2  A: 

The quantifier + means one or more repetitions. But /param_one/ would require zero or more repetitions. So try the * quantifier to have zero or more repetitions:

RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]*)$ index.php?p=$1&l=$2
Gumbo
I <3 you. Thank you so much man.
Kirill
Kirill
@Kirill: What URL did you test that with?
Gumbo
Sorry, I should have been clearer. Omitting param 2 and 3 and only while supplying the first one gives a 404, while supplying all 3 works fine. I did use the trailing slash (I modified both).site.com/one - 404, site.com/one/two/three works fine
Kirill
@Kirill: You also need to make the separating `/` optional with `/?`.
Gumbo