2016-02-08 95 views
2

有問題。 我有一個頁面名稱users.php此頁面顯示所選用戶和我的正常連接是這樣users.php?member=John然後我改變它來清潔網址這樣users/member/John但我的問題是,當你使用正常的URL它會正常工作訪問的頁面,但現在我有重寫它在我的.htaccess它會帶我到用戶的頁面,但沒有信息顯示它將是空的國防部重寫和PHP國防部重寫的.htaccess和PHP不工作在get方法

這裏是我的.htaccess

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+users\.php\?member=([^\s&]+) [NC] 
RewriteRule^users/member/%1? [R=301,L] 
RewriteRule ^users/member/([^/]+)/?$ users.php?member=$1 [L,QSA] 

這是我的PHP代碼

<?php 

    if(isset($_GET['member'])) { 


include($root . '_inc/dbconn.php'); 

try{ 

     $db_conn = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME,DB_USERNAME,DB_PASSWORD); 
     $db_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     $stmtData = $db_conn->prepare("SELECT * FROM users WHERE username=:getmember "); 
     $stmtData->bindParam(":getmember", $_GET['member']); 
     $stmtData->execute(); 

    $UserData = $stmtData->fetch(PDO::FETCH_OBJ); 
    if ($UserData) { 
     $Dusername = $UserData->username; 
     $Dphoto = $UserData->photo; 
     $Demail = $UserData->email; 

     } 
} 
catch(PDOException $e) 
    { 
    echo "Error:" . $e->getMessage(); 
    } 
$db_conn = null; 
} 

?> 
<?php echo $Dusername;?> 

回答

0

的問題是你RewriteCond。你必須否定條件(注符號「!」):

RewriteCond %{REQUEST_URI} !^[A-Z]{3,}\s/+users\.php\?member=([^\s&]+) [NC] 
RewriteRule ^users/member/%1? [R=301,L] 
RewriteRule ^users/member/([^/]+)/?$ users.php?member=$1 [L,QSA] 

您可以在online htaccess tester測試重寫規則。

+0

仍然是同樣的事情 – Micheal