.htaccess - Mod-rewrite and php not working in in get method -
having problem in mod-rewrite .htaccess , php. have page name users.php
page display selected user , normal link users.php?member=john
changed clean url users/member/john
problem when visit page using normal url work fine have rewrite in .htaccess take me user page not information display empty
here .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]
here php code
<?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 * users 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;?>
the problem rewritecond
. have negate condition (note '!' 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 rewrite rules on online htaccess tester.
Comments
Post a Comment