0
當訪問者訪問我的網站並輸入以下形式的網址myWebsiteName/userName時,它們被轉發到一個腳本,該腳本查找與userName關聯的成員標識,然後轉發到配置文件頁面。使用mod_rewrite更改網址
問題是url更改爲myWebsite/member-profile?member_id形式,但我希望它保持原樣輸入到url中。我相信這與mod_rewrite有關,但不知道哪些條件或規則適用。
下面是我的.htaccess文件和查找成員配置文件的腳本的代碼。有什麼建議嗎?
SuPHP_ConfigPath /home/helcupor/public_html
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
#for files, append .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
#for vanity urls redirect to url2id.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ url2id.php?vanityName=$1 [L]
AuthUserFile "/home/helcupor/.htpasswds/public_html/passwd"
ErrorDocument 404 /routing.php
#AuthName "/admin/"
url2id.php
<?php
include("includes/functions-and-vars.inc");
$connection = mysql_connect('localhost','','');
$vanityName = explode("/",$_SERVER['REQUEST_URI']);
if(strlen($vanityName['1'])>0) {
$vanityName = mysql_real_escape_string($vanityName['1'],$connection);
$validSpecialChars = array('-', '_');
if(ctype_alnum(str_replace($validSpecialChars, '', $vanityName))) {
$user = db_connect("SELECT mem_id FROM users WHERE vanity_url = '$vanityName' LIMIT 1");
if(mysql_num_rows($user)==1) {
$newArray = mysql_fetch_array($user);
$memID = $newArray['mem_id'];
header('location:member-profile.php?mem_id='.$memID.'&token=1');
exit;
}
else {
header('location:advanced-search.php?error=user_not_found');
exit;
}
}
else {
header('location:advanced-search.php?error=user_not_found');
exit;
}
}
else {
header('location:index.php');
exit;
}
//echo '<br>' . $vanityName;
?>
不,沒有工作。現在,我認爲解決方案是從url2id.php腳本中構建成員配置文件,或者只是將代碼從url2id.php添加到member-profile.php腳本中,並在我的.htaccess中將url2id.php更改爲member-profile.php –
它會工作,我已經更新。 – Vinay
我能夠通過做我上面陳述的問題來解決問題! –