PHP、MySQL、および.htaccess
(ファイルを使用するのはこれが初めて.htaccess
です) を使用して、ユーザーのプロファイル ページを作成しています。
昨日は完全に機能し、このような URL を作成できました(http://localhost/Unnamed site 2/resources/*username*)
が、今日はできるようになり、ブラウザに次のエラー メッセージが表示されます。
内部サーバーエラー
サーバーで内部エラーまたは構成ミスが発生したため、リクエストを完了できませんでした。サーバー管理者の admin@localhost に連絡して、エラーが発生した時刻と、エラーの原因となった可能性のある操作を知らせてください。このエラーの詳細については、サーバー エラー ログを参照してください。
どうすればこれを解決できますか? 関連するコードは次のとおりです。
profile.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