Php 用Get重写Mod

Php 用Get重写Mod,php,mod-rewrite,Php,Mod Rewrite,我已经在这里运行了以前的尝试来解决这个问题,但似乎无法解决这个问题。我得到的是一个用户页面user.php,其中包含类似user.php?u=Chris的内容 我试着重写如下 RewriteEngine On RewriteRule ^user/([a-zA-Z0-9]+)/$ user.php?u=$1 [NC] 因此它显示为www.mydomain.com/user/chris 每次我试图进入页面时,我都会遇到我自己的消息“未记录”…来自下面的msg=notlogged部分。我认为重写后g

我已经在这里运行了以前的尝试来解决这个问题,但似乎无法解决这个问题。我得到的是一个用户页面user.php,其中包含类似user.php?u=Chris的内容

我试着重写如下

RewriteEngine On
RewriteRule ^user/([a-zA-Z0-9]+)/$ user.php?u=$1 [NC]
因此它显示为www.mydomain.com/user/chris

每次我试图进入页面时,我都会遇到我自己的消息“未记录”…来自下面的msg=notlogged部分。我认为重写后get变量有问题。这是真的吗?还是我看错了?如何维护get变量,以便在数据库中检查u

<?php
include_once("../includes/check_login_status.php");
// Initialize any variables that the page might echo
$u = "";
$userlevel = "";
$profile_pic = "";
$profile_pic_btn = "";
$avatar_form = "";
$joindate = "";
$lastsession = "";
// Make sure the _GET username is set, and sanitize it
if(isset($_GET["u"])){
$u = preg_replace('#[^a-z0-9]#i', '', $_GET['u']);
} else {
   header("location: http://www..com");
    exit(); 
}

// Select the member from the users table
$sql = "SELECT * FROM transactions WHERE username='$u' AND activated='1' LIMIT 1";
$user_query = mysqli_query($db_conx, $sql);
// Now make sure that user exists in the table
$numrows = mysqli_num_rows($user_query);
if($numrows < 0){
header("location: http://www..com/message.php?msg=notlogged");
    exit(); 
}
// Check to see if the viewer is the account owner
$isOwner = "no";
if($u == $log_username && $user_ok == true){
$isOwner = "yes";
$profile_pic_btn = '<a href="#" onclick="return false;" onmousedown="toggleElement(\'avatar_form\')">Toggle Avatar Form</a>';
$avatar_form  = '<form id="avatar_form" enctype="multipart/form-data" method="post" action="php_parsers/photo_system.php">';
$avatar_form .=   '<h4>Change your avatar</h4>';
$avatar_form .=   '<input type="file" name="avatar" required>';
$avatar_form .=   '<p><input type="submit" value="Upload"></p>';
$avatar_form .= '</form>';
}
else 
var_dump($_GET);
//header("location: http://www..com/message.php?msg=notlogged");
// Fetch the user row from the query above
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$profile_id = $row["id"];
$userlevel = $row["userlevel"];
$avatar = $row["avatar"];
$signup = $row["signup"];
$email = $row["email"];
$username = $row["username"];
$lastlogin = $row["lastlogin"];
$joindate = strftime("%b %d, %Y", strtotime($signup));
$lastsession = strftime("%b %d, %Y", strtotime($lastlogin));
}
$profile_pic = '<img src="user/'.$u.'/'.$avatar.'" alt="'.$u.'">';
if($avatar == NULL){
$user1 = "";
$profile_pic = '<img src="images/avatardefault.jpg" alt="'.$user1.'">';
$username ="'.$email.'";
}
?>
<?php 
$coverpic = "";
$sql = "SELECT filename FROM photos WHERE user='$u' ORDER BY RAND() LIMIT 1";
$query = mysqli_query($db_conx, $sql);
if(mysqli_num_rows($query) > 0){
$row = mysqli_fetch_row($query);
$filename = $row[0];
$coverpic = '<img src="user/'.$u.'/'.$filename.'" height="200" width="200" alt="pic">';
}
?>

<?php
// If the page requestor is not logged in, usher them away
$notification_list = "";
$sql = "SELECT * FROM notifications WHERE username LIKE BINARY '$log_username' ORDER BY date_time DESC";
$query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($query);
if($numrows < 1){
$notification_list = "You do not have any notifications or you're viewing a fellow traders profile";
} else {
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$noteid = $row["id"];
$initiator = $row["initiator"];
$app = $row["app"];
$note = $row["note"];
$date_time = $row["date_time"];
$date_time = strftime("%b %d, %Y", strtotime($date_time));
$notification_list .= "<p><a href='user.php?u=$initiator'>$initiator</a> | $app<br />$note</p>";
}
}
mysqli_query($db_conx, "UPDATE transactions SET notescheck=now() WHERE username='$log_username' LIMIT 1");
?>

$numrows不应小于零。即使它是false或null,在松散比较中仍然等于零。这是导致notlogged消息的唯一代码路径吗?您确定处理notlogged in message.php的逻辑没有错误吗?基本的调试和错误处理是正确的。暂时删除标头重定向,并检查$numrows的内容以及$user\u query的内容。确保它返回,如果没有返回,请查看mysqli_error$db_conxi,如果它们不在数据库中,则没有进一步访问的权限。此时,它们将被定向到消息页…如果找到它们,则它们可能会继续..在我添加重写之前,一切都正常*。您是否使用var_dump$来确保传递值?这应该是调试的第一步。您是否有其他可能与此匹配的后续重写规则?您没有[L]标志……我还注意到您的示例是www.mydomain.com/user/chris,但是您的重写规则需要一个尾随斜杠,如www.mydomain.com/user/chris/中所示,没有它将无法匹配。
RewriteEngine On
        RewriteCond %{SERVER_PORT} 80
        RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^/?$ "http\:\/\/www\.mydomain\.com\/" [R=301,L]

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^user/([a-zA-Z0-9]+)/$ user.php?u=$1 [NC]