2011-01-26 141 views
0

讓我們假設你有一個這樣的網址在鏌鋣埃沃URL段基於重定向

進入

www.zipit.com.org/reference/toamovie/

,如果我有一個名爲頁面toamovie其父被稱爲reference

但是當有人輸入那個網址我希望它做相當於這個

www.zipit.com.org/reference.html?myvar=toamovie

此外,更重要的是, 我希望得到的結果是更多的像這樣的,其中12 wouls是一個文檔

`www.zipit.com.org/reference.html?myid=12' 的ID

我想知道這是否完全可能與modx Evolution.I'm認爲這應該是可能的一些htaccess魔術,以及無論如何第一部分。我怎麼能得到這個文件的價值?這對於htaccess來說是非常難以訪問的,所以需要另一部分才能插入數據庫並獲得該值。

回答

0

應該可以使用在「OnPageNotFound」事件上調用的自定義插件。

<?php 
$url = $_SERVER['REQUEST_URI']; //get the url   
//split the url into pieces and remove empty values 
$pieces = array_filter(explode('/', $url)); 

//reset the array keys 
$temp = array(); 
foreach ($pieces as $piece) { 
    $temp[] = $piece; 
} 
$pieces = $temp; 

//basic checking of the url 
if (count($pieces) == 2) { 
    $modx->sendRedirect('http://www.zipit.org/' . $pieces[0] .".html?myid=" . $pieces[1]); 
} 
?> 

記住,插件不裹在PHP標籤。 此外,該腳本會將任何不正確的URL傳遞給zipit.org。一些錯誤處理可能是需要的。