apache - htaccess redirect when directory exists -
this question has answer here:
for making friendly urls, following htaccess code applied:
rewriteengine on rewritecond %{the_request} /.+?\.php[\s?] [nc] rewriterule ^ - [f] rewriterule ^([^/\.]+)$ index.php?id1=$1 [nc,l,qsa] rewriterule ^([^/\.]+)/([^/\.]+)$ index.php?id1=$1&id2=$2 [nc,l,qsa]
this works for:
mydomain.com/pages
mydomain.com/index.php?id1=pages
mydomain.com/pages/xyz
mydomain.com/index.php?id1=pages&id2=xyz
also, when enter mydomain.com/index.php?id1=pages&id2=xyz
manually in url, redirects mydomain.com
.
now, when enter mydomain.com/templates
templates directory exists, redirects mydomain.com/templates/?id1=templates
edit 1:
i tried adding line in vain:
rewritecond %{request_filename} !-d rewritecond %{document_root}/$1\.php -f [nc] rewriterule ^(.+?)/?$ /$1.php [l]
how shall avoid condition (when directory name exists) using htaccess?
rewriteengine on rewritecond %{the_request} /.+?\.php[\s?] [nc] rewriterule ^ - [f] #serve dirs without rewriting rewritecond %{request_filename} -d rewriterule ^ - [l] ##### rewriterule ^([^/\.]+)$ index.php?id1=$1 [nc,l,qsa] rewriterule ^([^/\.]+)/([^/\.]+)$ index.php?id1=$1&id2=$2 [nc,l,qsa]
Comments
Post a Comment