apache - Redirect nested directories to a .php -
i want redirect legitimate directory names below directory php file. found this answer seems saying can in root .htaccess:
rewriteengine on rewriterule /([^/]+) processdir.php?dir=$1 [b,qsa]
i think i'm looking for, there way to:
limit directories, allow nested directories? only filter directories: don't want process files.
i think you're looking rewritecond
, lets conditionally apply rewrite rules. 1 checks if directory:
rewritecond %{request_filename} -d
you utilize putting above rewriterule
, this:
rewriteengine on rewritecond %{request_filename} -d rewriterule /([^/]+) processdir.php?dir=$1 [b,qsa]
this work either method in question or answer, of import thing note -d
flag checks request valid directory first before applying rule, seemed want.
the sec part of question, gather, nested directories. regex, stands, looking 1 directory downwards (no slashes). if want alter that, can this:
rewriteengine on rewritecond %{request_filename} -d rewriterule /?some_dir/(.*) processdir.php?dir=$1 [b,qsa]
this take valid directory below some_dir
, feed php file.
one lastly thing note don't need set of root .htaccess
file. can set .htaccess
file in directory want rewrite. there's not much of difference in doing 1 way or other, i've found can simplify syntax bit if you're not sure you're doing.
apache .htaccess
No comments:
Post a Comment