Home Ask Login Register

Developers Planet

Your answer is one click away!

Micheal February 2016

Mod-rewrite and php not working in in get method

Having problem in mod-rewrite .HTACCESS and php. I have a page name users.php this page display selected user and my normal link is like this users.php?member=John then i changed it to clean url like this users/member/John but my problem is when you visit the page using normal url it will work fine but now i have rewrite it in my .HTACCESS it will take me to user page but not information will display it will be empty

Here is my .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]



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

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


      $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']);

    $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;?>


take February 2016

The problem is your RewriteCond. You have to negate the condition (note the '!' sign):

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]

You can test your Rewrite Rules on online htaccess tester.

Post Status

Asked in February 2016
Viewed 1,136 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life