0

我有一个具有以下链接结构的 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>";
}
4

2 回答 2

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]

请注意RewriteCond第 6 行中的 :它告诉 mod_rewrite 不要重写wisper/businesspage.php,从而避免循环。

于 2013-08-01T07:27:10.650 回答
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 创建无限循环

于 2013-08-01T05:32:36.053 回答