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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -