Php mod_rewrite代码未重定向到预期的链接结构


Php mod_rewrite code not redirect to expected link structure

我有一个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

.htaccess代码:

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

.htaccess代码

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]

试试这个

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]   
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>";