[英]Rewriting urls in Concrete5
因此,我正在使用Concrete5作為CMS,並且試圖重寫一個已經重寫的URL。
因此,我有這個網址http://url.com/index.php?cID=144&id=4 ,它將改寫為http://url.com/rengas?id=1 。
但是,我想將其重寫為http://url.com/rengas/1 ,到目前為止,我一直無法做到這一點。
所以這是我的htaccess:
# -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
# -- concrete5 urls end --
RewriteEngine On
RewriteRule ^rengas/([^/]*)$ /index.php?cID=144&id=$1 [L]
如您所願,我使用http://www.generateit.net/mod-rewrite/index.php生成了規則,該規則做得很好,但是這次卻使我失敗了。
假設您的單個頁面稱為testpage.php,位於root / single_pages / testpage.php
通過創建控制器,您可以在最后一個斜杠之后捕獲數據
例如:mysite.com/testpage/123
您的控制器文件位於:root / controllers / testpage.php
控制器的內容(要使其適應您的代碼,請不要忘記調整類的名稱,在您的示例中將是... rengasController擴展...)==
<?php
defined('C5_EXECUTE') or die("Access Denied.");
class testpageController extends Controller {
public function view($id){
//here you can do anything with the captured id.
// here you can set the id to give it to your single page using following code:
$this->set('id', $id);
// the code above will make a variable $id to use in the code of the single page
}
}
?>
我知道上面的解釋可能有點難以理解,因此這里有一些鏈接可以更好地理解Concrete5中的MVC(單頁和控制器)系統:
http://www.concrete5.org/documentation/recorded-trainings/single-pages/basic-application-development-part-one/ (請參閱創建單個頁面控制器並查看)
http://www.concrete5.org/documentation/how-tos/developers/basic-mvc-in-concrete5/ (請參閱單頁控制器)
這是我寫的一個示例(大約14天可用): http : //ge.tt/api/1/files/9eheDrP1/0/blob?download
如果上面的文件不可用或者您不願下載,則這里有一個代碼粘貼: http ://pastie.org/8906708
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.