【问题标题】:url rewrite rules in htaccess with php mysql使用 php mysql 在 htaccess 中重写 url 规则
【发布时间】:2016-03-15 18:32:57
【问题描述】:

如何编写链接下面给出的url重写规则。

  1. 匹配页面的原始网址:

    http://www.cricmelive.tv/live/09876/barisal_bulls_vs_chittagong_vikings_t20
    

现在需要网址:

    http://www.cricmelive.tv/live/09876/barisal_bulls_vs_chittagong_vikings_t20

2。频道 Catgry 的原始网址:

http://www.cricmelive.tv/live/category.php?id=1 

现在需要的网址为:

http://www.cricmelive.tv/live/sports

3。 Sports Catgry 的原始网址:

http://www.cricmelive.tv/live/index.php?catid=1 

现在需要的网址为:

http://www.cricmelive.tv/live/cricket

4。频道页的原始网址:

http://www.cricmelive.tv/live/channel-page.php?cid=45   

现在需要:

http://www.cricmelive.tv/live/espn-3-live-streaming

我是你重写的新手。我再发一次。帮帮我,如何重新编写重写url代码原来的url

【问题讨论】:

  • 前两个链接示例相等(编号 1)。
  • 数字 2、3 和 4 不明确。它们具有相同的模式。所以重写规则将匹配它们。您如何确定差异?
  • 如何将@Progrock http://localhost/live/index.php?catid=2 改写成http://localhost/live/cricket

标签: php .htaccess url mod-rewrite url-rewriting


【解决方案1】:

我明白你在做什么,但它不是那样工作的。查询字符串中的参数在sql的后端使用$_GET在db中查找相关记录。

catid=45 不直接转换为 cricket - 在数据库中可能 catid=1 可能是 cricket 但网络服务器不知道这种关系,所以你需要改变你的 sql 查询,以便它使用 @ 987654326@作为where子句中的参数而不是1。

例如:

http://www.cricmelive.tv/live/1 

that could be expressed easily with a rewrite rule, such as:
RewriteRule ^live/([0-9]+)$ live/index.php?catid=$1 [NC,L]


select * from table where category='cricket'
RewriteRule ^live/([0-9a-zA-Z]+)$ live/index.php?category=$1 [NC,L]

【讨论】:

  • 如何将http://localhost/live/index.php?catid=2改写成http://localhost/live/cricket@RamRaider
  • 正如你之前所说的RewriteRule ^live/([0-9]+)$ live/index.php?catid=$1 [NC,L] 它不起作用@RamRaider
猜你喜欢
  • 1970-01-01
  • 2011-12-06
  • 2016-11-19
  • 1970-01-01
  • 1970-01-01
  • 2017-11-14
  • 2014-05-18
  • 1970-01-01
相关资源
最近更新 更多