2016-04-22 5 views
0

以下のようにするにはどうすればよいでしょうか.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 a file 
/sp/siteb => /check.php?page=siteb 

/sp/index.php , /sp/login.php => no redirect 
私は、ユーザーがログインしているかどうかを確認し、それらが

を/login.phpするために、そのサイトのリダイレクトのためにログインしていない場合は、/ SP /シティアにリダイレクトするシティアのためのPHPを使用してDBを確認したい

私は、イム本当に.htaccessのないマスター

RewriteEngine On 
RewriteCond %{REQUEST_URI}/
RewriteRule ^\/(.*)$ sp/check.php?path=$1 [L] 
+0

何をあなたがすることによって意味ですか "が、動作しませんか"? –

+0

@MatthewCliattそれはリダイレクトされません – tsukimi

+0

あなたの投稿にこの情報を含めたいと思います。 –

答えて

0

は私が変更された.htaccessファイル

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 
でこれを解決し、SPフォルダに、.htaccessを以下しようとしたが、リダイレクトdoes notの

check.php

<?php 
//htaccess redirects here for sitepreview subdomains, then do authentication check and output the html 
//cant redirect to page or get 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(); 
} 
+1

正確に修正した方法を拡張できますか?それは将来他人を助けるかもしれない。 – Bono

+1

@bono updated .... – tsukimi

関連する問題