php - HTACCESS | Adding a second rewrite rule? -
i'm trying write .htaccess support 2 vanity url's, code speak i'm not .htaccess.
rewriterule ^([a-za-z0-9-]+)/?$ index.php?p=$1&s=$2 [l,qsa] upon going example http://website.com/home/test
i 404, $_get["p"] still returns home if go website.com/home.
why getting 404 when adding in second variable in url?
you 404 because /home/test not match expression ^[a-za-z0-9]+/?$. second group after first / exists beyond $ string terminator. need add second () group, optional. have replaced a-za-z0-9 character classes [^/]+ matches next slash.
the (?:) indicates non-capturing group encompasing first /, capturing group () inside retrieve $2 component. entire construct made optional ? before final $ terminator.
rewriteengine on rewriterule ^([^/]+)(?:/([^/]+)/?)?$ index.php?p=$1&s=$2 [l,qsa]
Comments
Post a Comment