繁体   English   中英

用php和mysql重写URL规则

[英]url rewrite rules with php and mysql

我是写URL重写规则的新手。 您能帮我编写重写规则吗? 我当前的浏览器网址是

http://localhost/live/match-page.php?mid=770&sid=7

我在下面给出了该网址的锚标记

<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 file然后在下面显示我的浏览器网址,如下所示:

http://www.cricmelive.tv/live/177/south-africa-v-india-test-live-streaming
http://www.cricmelive.tv/live/Basketball-live-streaming

如何为网址重写模式设置锚点数?

的确,我对此进行了新查询? 并传递给数据库。 如果有可能怎么做。

希望这些帮助。 不过,我有点困惑,您说您需要同时使用midsid但上面的示例有所不同〜一个具有midsid参数,而另一个仅具有一个,大概是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进行链接将丑陋的查询字符串插入新的漂亮网址中。 有关后者的示例,请查看Anubhava的一些帖子〜他是大师!

将此代码添加到htaccess文件

 Options -MultiViews +FollowSymLinks
 RewriteEngine On
 RewriteRule ^/?live/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /match-page.php?mid=$1&sid=$2 [L]

在match-page.php上,假设您添加了http://www.cricmelive.tv/live/770/7/Basketball-live-streaming类的http://www.cricmelive.tv/live/770/7/Basketball-live-streaming ,则可以获取midsid http://www.cricmelive.tv/live/770/7/Basketball-live-streaming

编辑

将此代码添加到htaccess文件

 Options -MultiViews +FollowSymLinks
 RewriteEngine On
 RewriteRule ^/?live/([0-9]+)/([0-9]+)/?$ /match-page.php?mid=$1&sid=$2 [L]

您要问的是如何用更干净的方案(干净的URL)替换当前的URL模式。

后台的匹配页面逻辑很可能使用“ mid”和“ sid”对结果进行某种数据库查找。

最小的更改可能是更改为新的url格式,如下所示:

http://www.example.com/live/MID/SID/text-descriptor
http://www.example.com/live/770/7/south-africa-v-india-test-live-streaming

.htaccess

RewriteEngine On
RewriteRule ^live/([0-9]+)/([0-9]+)/ match-page.php?mid=$1&sid=$2 [L]

然后更改您的链接以输出新模式:

$href = '/live/' . $rec->ID . '/' . $rec->stream_id . '/' . $rec->text; // text from category or title (isn't needed by script.)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM