regex - RewriteRule acting strange -
i want url this: localhost/dir/images/pic1.jpg
to rewriten to: localhost/dir/subdir/index.php?folder=images&picture=pic1.jpg
so put simple .htaccess file in localhost/dir/:
rewriteengine on rewriterule ^(.*)/(.*)$ subdir/index.php?folder=$1&picture=$2 [l] and expect folder='images' , picture='pic1.jpg' in localhost/dir/subdir/index.php instead have folder='subdir' , picture='index.php'
strange thing when modify .htaccess file call index.php same directory (not 'subdir') works well:
rewriteengine on rewriterule ^(.*)/(.*)$ index.php?folder=$1&picture=$2 [l] i folder='images' , picture='pic1.jpg' in localhost/dir/index.php script
that happening because rewrite rule looping , matching target string subdir/index.php pattern .*/.*.
use condition stop loop:
rewriteengine on # if request not valid directory rewritecond %{request_filename} !-d # if request not valid file rewritecond %{request_filename} !-f rewriterule ^(.*)/(.*)$ subdir/index.php?folder=$1&picture=$2 [l]
Comments
Post a Comment