Monday 15 April 2013

regex - htacess RewriteRule for /category/page -



regex - htacess RewriteRule for /category/page -

in .htaccess defined such rewrite rule

rewriterule ^([a-za-z0-9_-]+)$ ___show-content.php?$1

created file ___show-content.php includes code

echo (ltrim($_server['query_string'],'/')). '<br/>';

if type www.mydomain.com/some-page $_server['query_string' /some-page. works expected.

but if type www.mydomain.com/some-page/another-page, see not found requested url /some-page/another-page not found on server. see nil $_server['query_string'. if 1 trailing slash (after domain name), works ok, if more one, not works.

what need modify rewriterule work more 1 trailing slash in url?

that because regex capture uri allowing 1 , more of [a-za-z0-9_-] characters in it.

make rule as:

rewriterule ^([\w/-]+)$ ___show-content.php?$1 [l,qsa]

regex apache .htaccess mod-rewrite

No comments:

Post a Comment