0

我有一个 php 页面,它显示从 index.php 页面重定向的用户业务页面。

一些 Index.php 页面代码如下:

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>";    
?>
<img src="<?php echo "$upload_directory/$profile_pic_d"; ?>" width="99" 
height="100"/>
<?php
echo "</div>";
}

现在它重定向到这个链接:

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

所以我试图重定向此链接以显示如下所示:

http://localhost/wisper/creativeartbd

.ht 访问代码:

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 [R=301,QSA,L]

但不幸的是它不起作用。代码有问题吗?

更新:

现在 index.php 页面代码如下:

echo "<h4><a href='$uname_d'>$uname_d</a></h4>";

但是链接被重定向到我不想要的这种样式,并且它的显示对象未找到:

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

我希望链接应该是这样的:

http://localhost/wisper/creativeartbd

.ht 访问代码

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

2 回答 2

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

你的代码告诉浏览器去http://localhost/wisper/businesspage.php?profile=creativeartbd,所以当它点击链接时浏览器当然会去那里。mod_rewrite 在服务器端,而不是浏览器端。您需要确保您的链接看起来像您希望的那样:

echo "<h4><a href='/wisper/$uname_d'>$uname_d</a></h4>";    
于 2013-08-01T09:19:09.790 回答
0

试试这个

RewriteEngine On
RewriteBase /wisper/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.*?)$ businesspage.php?profile=$1 [R=301,QSA,L]

它将每个 url 点击传递给businesspage.php?profile=?您应该自定义链接以区分用户个人资料链接和其他网站链接

例如

echo "<h4><a href='profile/$uname_d'>$uname_d</a></h4>"; 

你的重写规则是

 RewriteRule ^profile/(.*?)$ businesspage.php?profile=$1 [R=301,QSA,L]   
于 2013-08-01T09:21:34.047 回答