regex - RewriteRule for multiple URL matches in one line -
i use following lines in .htaccess file rewrite several subdirectory urls root of website:
rewriterule ^work(.*)$ $1 rewriterule ^why-me(.*)$ $1 rewriterule ^prices(.*)$ $1 rewriterule ^contact(.*)$ $1 however, there way of expressing in 1 line instead?
i tried:
rewriterule ^(work|why-me|prices|contact)(.*)$ $1 but (unsurprisingly, given complete lack of knowledge when comes regexes), didn't work , resulted in these urls giving me 404 errors.
rewriterule "^(work|why-me|prices|contact)(.*)$" "$2" or
rewriterule "^(?:work|why-me|prices|contact)(.*)$" "$1" $1 refers first capturing group, whatever defined in first set of parenthesis. since you've created set within parenthesis, $1 no longer refers follows, instead contains work,why-me, etc.
the first solution needs $2 because $1 1 of: work,why-me, etc. , $2 whatever follows it.
the second solution works using non-capturing group first group (it isn't numbered), (.*) put it's part $1 instead of $2.
Comments
Post a Comment