dongqiang8683 2013-10-29 10:25
浏览 55
已采纳

too long

I am not familiar with url rewrite at all, so I have probably simple question for somebody that knows the stuff. I have ecommerce site and currently item url looks like this www.blizuecomm.net/www/item.php?id=399&ITEM-NAME I get this kind of URL with code on category page that looks like this

<a href="item.php?id=<?=$values[$i]['gitemid']?>&amp;<?=cleanString($values[$i]['gname'])?>

I get clean string using this code

<?
function cleanString($string, $separator = '-'){
$accents = array('Š' => 'S', 'š' => 's', '?' => 'Dj', 'ð' => 'dj','Ž' => 'Z', 'ž' => 'z', 'È' => 'C' , 'è' => 'c', 'Æ' => 'C' , 'æ' => 'c');
$string = strtr($string, $accents);
$string = strtoupper($string);
$string = preg_replace('/[^a-zA-Z0-9\s]/', '', $string);
$string = preg_replace('{ +}', ' ', $string);
$string = trim($string);
$string = str_replace(' ', $separator, $string);
return $string;
}
?>

What should I write in .htaccess file in order to get ULR that looks like this: www.blizuecomm.net/www/ITEM-NAME or www.blizuecomm.net/ITEM-NAME

  • 写回答

1条回答 默认 最新

  • dse323222 2013-10-29 10:32
    关注

    The easiest thing to do is probably make it look like: www.blizuecomm.net/www/id/ITEM-NAME because otherwise your item.php script isn't going to get an ID. That'll require you to add this in the htaccess file in your www folder:

    RewriteEngine On
    RewriteBase /www/
    
    RewriteCond %{THE_REQUEST} \ /www/item\.php\?id=([0-9]+)&([^&\ ]+)
    RewriteRule ^ %1/%2? [L,R=301]
    
    RewriteRule ^([0-9]+)/(.*)$ item.php?id=$1&$2 [L,QSA,NE]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?