2015-12-10 17 views
0

如何写下面的URL改写规则链接。使用php mysql的htaccess中的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.原始网址体育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 

否W需要为:

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

我是新的你的重写。我再次发布它。帮帮我,怎么写重写url代码再次原始url

+0

前两个链路的例子是相等的(号码1)。 – Progrock

+0

数字2,3和4是不明确的。它们具有相同的模式。所以重写规则会匹配所有的。你如何确定差异? – Progrock

+0

如何将它重写为'http:// localhost/live/index。'如何将它重写为'http:// localhost/live/cricket' – SAJ

回答

0

我看到你正在做什么,但它不这样工作。查询字符串中的参数用于sql的后端,以便使用$_GET在db中查找相关记录。

catid=45不会直接转化为cricket - 数据库或许catid=1可能是cricket但Web服务器并不知道这种关系,所以你需要改变你的SQL查询,使得使用cricket的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] 
+0

@Progrock'http://localhost/live/index.php?catid = 2' php?catid = 2'转换成'http:// localhost/live/cricket' @RamRaider – SAJ

+0

正如你在'RewriteRule^live /([0-9] +)$ live/index.php?catid = $ 1 [NC ,L]'不工作@RamRaider – SAJ