.htaccess - I want my users to only access my php files, if they try to access the folders I want to include my page 404 file -
i have query string include pages, in homepage see below , working fine, im including pages fine.
but wrong happening , im not finding how can solve this.
i try expain isse example: have folder "teachers" inside have 2 pdf documents , page "documents.php". acess documents page, im acessing: "htp://localhost/website/teachers/documents", , working fine.
but if acess "htp://localhost/website/teachers/", im able acess pdf documents , page see in image below.
but dont want this, want if user tries acess "htp://localhost/website/teachers/", want include 404 file (require_once('inc/404.php');
)
my query string:
@$url = $_get['url']; $url = explode('/', $url); $url[0] = ($url[0] == null ? 'index' : $url[0]); if(file_exists('inc/'.$url[0].'.php')){ require_once('inc/'.$url[0].'.php'); } elseif(file_exists($url[0].'/'.$url[1].'/'.$url[2].'.php')){ require_once($url[0].'/'.$url[1].'/'.$url[2].'.php'); } elseif(@file_exists($url[0].'/'.$url[1].'.php')){ require_once($url[0].'/'.$url[1].'.php'); } else{ require_once('inc/404.php'); }
do see im doing wrong not having result want?
my htaccess file:
rewriteengine on rewritecond %{script_filename} !-f rewritecond %{script_filename} !-d rewriterule ^(.*)$ index.php?url=$1
there easier solution.
add line beginning of .htaccess file:
options -indexes
this way, won't able see folder contents.
edit: htaccess rule solution (which in website
folder)
errordocument 404 /website/inc/404.php rewriteengine on rewritebase /website/ rewriterule ^teachers/$ - [r=404,l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ index.php?url=$1 [l]
Comments
Post a Comment