php - limit subdirectories to logged in users -
how can below .htaccess ?
/sp/sitea => /check.php?page=sitea #no trailing forward slash /sp/sitea/ => /check.php?page=sitea #trailing forward slash /sp/sitea/index.php => /check.php?page=sitea/index.php #includes file /sp/siteb => /check.php?page=siteb /sp/index.php , /sp/login.php => no redirect
i want check db using php sitea see if user logged in , redirect /sp/sitea if not logged in site redirect /login.php
i tried .htaccess below , in sp folder, doesnt redirect, im not .htaccess master
rewriteengine on rewritecond %{request_uri} / rewriterule ^\/(.*)$ sp/check.php?path=$1 [l]
i solved modified .htaccess file
rewriteengine on rewriteoptions maxredirects=2 rewritebase / #dont check non pages rewritecond %{request_uri} !\.(gif|jpe?g|png|css|js)$ rewriterule ^(.*)/(.*)$ /sp/check.php?path=$1&path2=$2 [l,p] #p keeps address in bar after redirect
check.php
<?php //htaccess redirects here sitepreview subdomains, authentication check , output html //cant redirect page or redirect loop session_start(); $dir = $_get["path"]; $dir2 = $_get["path2"]; //echo $dir; if(!isset($_session['login_user'])){ header("location: /sp/index.php",true,301); exit(); }else { $name = $_session['login_user']["name"]; if($name == $dir) { $homepage = file_get_contents($_server['document_root'] . "/sp/$dir/" . (isset($dir2) && strpos($dir2, ".htm") ? $dir2 : "index.html") ); echo $homepage; } else { header("location: /sp/index.php",true,301); exit(); } exit(); }
Comments
Post a Comment