我是编写 url 重写规则的新手。你能帮我写重写规则吗?我当前的浏览器网址是
http://localhost/live/match-page.php?mid=770&sid=7
下面给出了该网址的我的 anchor 标记
<a target='_blank' href="match-page.php?mid=<?php echo $rec->ID?>&sid=<?php echo $rec->stream_id?>" style="color:#ffae00;"> <?php echo $rec->CatName; ?> - <?php echo $rec->Title; ?> </a>
如何编辑 .htaccess 文件
,然后显示我的浏览器网址,如下所示:
http://www.cricmelive.tv/live/177/south-africa-v-india-test-live-streaming
http://www.cricmelive.tv/live/Basketball-live-streaming
如何为 URL 重写模式设置 anchor 标记?
我确实对其进行了新查询吗?并传递到数据库。如果可以的话怎么做。
最佳答案
我希望这些有帮助。不过我有点困惑,你说你需要 mid
和 sid
但上面的例子是不同的〜一个同时有 mid
和sid
参数,而另一个只有一个,大概是 sid
#htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^live/(.+)$ live/match-page.php?sid=$1 [NC,L]
RewriteRule ^live/([0-9]+)/(.+)$ live/match-page.php?mid=$1&sid=$2 [NC,L]
/* php */
/* Match first style rewrite rule */
echo "<a target='_blank' href='/live/{$rec->stream_id}' style='color:#ffae00;'> {$rec->CatName} - {$rec->Title} </a>";
/* match second style rewrite rule */
echo "<a target='_blank' href='/live/{$rec->ID}/{$rec->stream_id}' style='color:#ffae00;'> {$rec->CatName} - {$rec->Title} </a>";
有两种方法可以使用 urlrewrite
- 一种如此处所示,您可以生成如图所示的链接以匹配重写规则中设置的模式,另一种方法是使用链接就像你最初拥有它们一样,并使用 apache 将丑陋的查询字符串变成新的、漂亮的 url。有关如何执行后者的示例,请查看 Anubhava 的一些帖子。 ~他是大师!
关于php - php和mysql的url重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34175874/