簡體   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