PHP的mod_rewrite的工作不正常 [英] Php mod_rewrite is not working properly

查看:186
本文介绍了PHP的mod_rewrite的工作不正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP页面下面的链接结构:

 的http://localhost/wisper/businesspage.php配置= creativeartbd
 

所以我想这个链接转换为以下方式:

 的http://本地主机/ WISPER / creativeartbd
 

的.htaccess配置

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-l
重写规则^ businesspage /(.*?)/(.*)$/ WISPER / businesspage.php?轮廓= $ 1 [QSA,L]
 

但不工作属性格式。我想我的code是错误的,你能PLZ告诉我?

感谢你。

更新:

我的PHP页面code是波纹管:

 回声< H4>< A HREF =?businesspage.php配置= $ uname_d'&GT​​; $ uname_d< / A>< / H4>中;
 

现在这显示此链接:

 的http://localhost/wisper/businesspage.php配置= creativeartbd
 

所以,我想告诉这个链接看起来是这样的:

 的http://本地主机/ WISPER / creativeartbd
 

更新2:

 而($水库= mysql_fetch_array($ SQL))
{

$中旬=(INT)$水库['中'];
$ uname_d = inputvalid($水库['的uname']);
$ profile_pic_d = inputvalid($水库['profile_picture']);
$中旬= base64_en code($中旬);
回声< D​​IV CLASS ='成员'>中;
//回声&其中; H4>&所述; A HREF =?businesspage.php轮廓= $ uname_d'&GT​​; $ uname_d&所述; / a取代;&所述; / H4>中;
回声&所述; A HREF ='/ WISPER / $ uname_d'&GT​​; $ uname_d&所述; / A>中;
?>
< IMG SRC =< PHP的回声$ upload_directory / $ profile_pic_d;?>中WIDTH =99
高度=100/>
< PHP
回声< / DIV>中;
}
 

解决方案

此规则集应该为你工作:

  RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-l
的RewriteCond $ 1!^ businesspage.php
重写规则^ WISPER /(.*?)$ WISPER / businesspage.php?轮廓= $ 1 [QSA,L]
 

请注意,的RewriteCond 在6号线:它告诉mod_rewrite的不重写 WISPER / businesspage.php ,从而避免环路。

I've a php page with following link structure:

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

So I'm trying to convert this link to following style:

http://localhost/wisper/creativeartbd

.htaccess configuration

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

But is not working propery. I think my code is wrong, can you plz tell me ?

Thank You.

Update:

My php page code is bellow:

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

Now It's show this link:

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

So I want to show this link to look like this:

http://localhost/wisper/creativeartbd

Update 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>";
}

解决方案

This ruleset should work for you:

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]

Please note the RewriteCond in the 6th line: it tells mod_rewrite not to rewrite the wisper/businesspage.php, thus avoiding loops.

这篇关于PHP的mod_rewrite的工作不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆