Php mod_rewrite运行不正常

时间:2013-08-01 05:25:11

标签: php .htaccess mod-rewrite

我有一个带有以下链接结构的php页面:

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]

但是不合作。我认为我的代码错了,你能告诉我吗?

谢谢。

更新:

我的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>";
}

2 个答案:

答案 0 :(得分: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/creativeartbd重写为wisper/businesspage.php?profile=$1会创建无限循环

答案 1 :(得分: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,从而避免循环。