doudiewen9435 2013-08-21 05:01
浏览 11

如何在php中的htaccess中为此url应用重写规则

url:
http://www.kashmirmart.com/display.php?cat_id=52&subcat_id=53&name=Woolen_Shawls

here cat id , subcate id and name are always dynamic values

i want to rewrite like this:

http://www.kashmirmart.com/parentname/subcatname/page

for example:

http://www.kashmirmart.com/handicraft-industry/kashmir-craft/Woolen_Shawls 

handicraft-industry is parent kashmir-craft is subcategory under the handicraft-industry Woolen_Shawls is the last detailed page listed in kashmir-craft

plz give me solution as early as possible thanks

  • 写回答

1条回答 默认 最新

  • dpqvwgr74759 2013-08-21 05:11
    关注

    I'll give you an example...You can modify based on your requirements.

    http://www.pets.com/show_a_product.php?product_id={a number}

    And you want to change them to look like this:

    http://www.pets.com/products/{a number}/

    In order to do so, you will need to use "regular expressions". These are patterns, defined in a specific format that the server can understand and handle appropriately. A typical pattern to identify a number would look like this:

    [0-9]+

    The square brackets contain a range of characters, and "0-9" indicates all the digits. The plus symbol indicates that the pattern will idenfiy one or more of whatever precedes the plus - so this pattern effectively means "one or more digits" - exactly what we're looking to find in our URL.

    The entire "pattern" part of the rule is treated as a regular expression by default - you don't need to turn this on or activate it at all.

    RewriteEngine On    # Turn on the rewriting engine
    RewriteRule    ^products/([0-9]+)/?$    show_a_product.php?product_id=$1    [NC,L]    # Handle product requests
    
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)