我第一次参与模组重写。我下面有一个可怕的链接,它会将您带到个人资料页面。在个人资料页面上,我根据 i 参数获取用户。
<a href="engineer-profile.php?country=<?php echo str_replace(' ','-',strtolower($row['country']));?>&area=<?php echo str_replace(' ','-',strtolower($row['area'])); ?>&i=<?php echo $row['id'];?>&name=<?php echo str_replace(' ','-',strtolower($row['name']));?> " class="btn btn-md btn-bitbucket"><i class="fa fa-user"></i> View Profile</a>
我一直在尝试重写 mod,因此链接如下所示
/uk/southport/23/公司名称/
到目前为止,我的 .htaccess 文件中有这个
RewriteEngine on
RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ engineer-profile.php?country=$1&area=$2&i=$3&name=$4 [L]
现在,如果我重组我的链接,使其看起来如下:
<a href="/<?php echo str_replace(' ','-',strtolower($row['country']));?>/<?php echo str_replace(' ','-',strtolower($row['area'])); ?>/<?php echo $row['id'];?>/<?php echo str_replace(' ','-',strtolower($row['name']));?> " class="btn btn-md btn-bitbucket"><i class="fa fa-user"></i> View Profile</a>
我收到页面未找到错误。我也试过了
<a href="engineer-profile/<?php echo str_replace(' ','-',strtolower($row['country']));?>/<?php echo str_replace(' ','-',strtolower($row['area'])); ?>/<?php echo $row['id'];?>/<?php echo str_replace(' ','-',strtolower($row['name']));?> " class="btn btn-md btn-bitbucket"><i class="fa fa-user"></i> View Profile</a>
我还检查了 mod 重写是否已打开,并且它可以很好地进行基本测试。有人可以解释一下我哪里出了问题以及如何解决它吗?
最佳答案
engineer-profile.php ( example )
--------------------------------
<?php
echo '<pre>';
print_r( $_GET );
echo '</pre>';
?>
<?php
$id=$row['id'];
$country=str_replace(' ','-',strtolower($row['country']));
$area=str_replace(' ','-',strtolower($row['area']));
$name=str_replace(' ','-',strtolower($row['name']))
echo "<a href='/$country/$area/$id/$name' class='btn btn-md btn-bitbucket'><i class='fa fa-user'></i>View Profile</a>";
?>
# .htaccess
# required format
# /uk/southport/23/company-name/
# the following requires that rewritebase is specified, viz:-
RewriteBase /
RewriteRule ^([a-zA-Z\_\-]+)/([a-zA-Z0-9\_\-]+)/([0-9]+)/([a-zA-Z0-9\_\-]+)(/?)$ /engineer-profile.php?country=$1&area=$2&i=$3&company=$4 [NC,L]
# there were a couple of omissions from original - this works now though. The demo engineer-profile.php will output the following
Array
(
[country] => uk
[area] => southport
[i] => 23
[company] => company-name
)
关于php - mod 重写动态 php 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31748045/