2013-08-01 40 views
0

我已經與下面的鏈接結構的PHP頁面:PHP的mod_rewrite的工作不正常

http://localhost/wisper/businesspage.php?profile=creativeartbd 

所以我想這個鏈接轉換爲以下樣式:

http://localhost/wisper/creativeartbd 

的.htaccess配置

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^businesspage/(.*?)/(.*)$/wisper/businesspage.php?profile=$1 [QSA,L] 

但是不工作propery。我認爲我的代碼錯了,你能告訴我嗎?

謝謝。

更新:

我的PHP頁面代碼波紋管:

echo "<h4><a href='businesspage.php?profile=$uname_d'>$uname_d</a></h4>"; 

現在它的顯示此鏈接:

http://localhost/wisper/businesspage.php?profile=creativeartbd 

所以,我想告訴這個鏈接看起來像這樣:

http://localhost/wisper/creativeartbd 

更新2:

while($res = mysql_fetch_array($sql)) 
{ 

$mid = (int) $res['mid']; 
$uname_d = inputvalid($res['uname']); 
$profile_pic_d = inputvalid($res['profile_picture']); 
$mid = base64_encode($mid); 
echo "<div class='members'>"; 
//echo "<h4><a href='businesspage.php?profile=$uname_d'>$uname_d</a></h4>"; 
echo "<a href='/wisper/$uname_d'>$uname_d</a>"; 
?> 
<img src="<?php echo "$upload_directory/$profile_pic_d"; ?>" width="99" 
height="100"/> 
<?php 
echo "</div>"; 
} 
+0

所以你想要相反?也就是說,重定向/wisper/businesspage.php?.../wisper/profilename?我認爲這不需要mod_rewrite,也許一個RedirectMatch可以滿足要求 –

+0

我想讓url看起來像這樣。 localhost/wisper/profilename(suppose- creativeartbd)。請檢查我的更新。 – Alex

+0

RedirectMatch? – Alex

回答

0

你做錯了嘗試這個

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteBase/
RewriteRule ^wisperpage/(.*?)$ wisper/businesspage.php?profile=$1 [QSA,L] 

您需要更改第一個URI部分,因爲重寫wisper/creativeartbdwisper/businesspage.php?profile=$1將創建無限循環

+0

好的,我正在嘗試。 – Alex

+0

爲什麼說服務器錯誤! – Alex

+0

@Alex這個規則會產生一個循環 –

0

此規則集應該適用於您:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteCond $1 !^businesspage.php 
RewriteRule ^wisper/(.*?)$ wisper/businesspage.php?profile=$1 [QSA,L] 

請注意第6行的RewriteCond:它告訴mod_rewrite不要重寫wisper/businesspage.php,從而避免循環。

+0

你可以用'[R = 301,QSA,L]替換'[QSA,L]'並告訴它重定向到哪個頁面? –

+0

檢查我的更新。 – Alex

+0

因此,如果你更新你的鏈接到'$uname_d'它會起作用。另外,請刪除一些評論:) –