我正在为使用 PHP、MySQL 和.htaccess
(这是我第一次使用.htaccess
文件)的用户创建个人资料页面。
昨天它运行良好,我能够制作这样的 URL,(http://localhost/Unnamed site 2/resources/*username*)
但今天我可以做到,浏览器给了我以下错误消息:
内部服务器错误
服务器遇到内部错误或配置错误,无法完成您的请求。请联系服务器管理员 admin@localhost 并告知他们错误发生的时间,以及您所做的任何可能导致错误的事情。服务器错误日志中可能提供有关此错误的更多信息。
我该如何解决这个问题?以下是相关代码:
配置文件.php
if (isset($_GET['u'])) {
$username = mysql_real_escape_string($_GET['u']);
if (ctype_alnum($username)) {
// Check that the user exists
$check = mysql_query("SELECT user_name, first_name FROM user WHERE user_name = '$username' ")or die(mysql_error());
if (mysql_num_rows($check) == 1) {
$get = mysql_fetch_assoc($check);
$username = $get['user_name'];
$fname = $get['first_name'];
} else {
// this line is to redirect the non-existent users to the index.php
echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/Unnamed Site 2/resources/index.php\">";
exit();
}
}
}
// echo "$username";
.htaccess
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1