[英]Redirect to dynamic sitemap or generate it through yiic?
我想為yii網站呈現動態站點地圖。 但是我沒有在URL管理器中做到這一點:
'urlManager'=>array(
'showScriptName'=>false,
'rules'=>array(
'sitemap.xml/*'=>'/site/sitemapxml',
array('site/sitemapxml', 'pattern'=>'sitemap.xml', 'urlSuffix'=>''),
...
所以我轉向.htaccess
並添加了這樣的重定向:
Redirect 301 /app3/sitemap.xml http://tarex.ru/app3/index.php/?r=site/sitemapxml
首先,您的規則不正確,請改用此規則:
'rules' => array(
'/sitemap.xml' => '/site/sitemapxml',
...
)
現在,關於您的問題,實際上並沒有那么重要,您更喜歡哪種方式,它們每個人都有其優點和缺點。
優點:
缺點:
解決方案:使用COutputCache篩選器進行緩存。 將此過濾器添加到您的SiteController中:
public function filters()
{
return array(
array(
'COutputCache + sitemap',
'duration' => 24 * 60 * 60 // cache for 24 hours
),
);
}
不要忘記在配置文件中配置cache
組件。 為此使用CFileCache 。 如果您不熟悉此主題,請閱讀《 Yii權威指南》的相應部分 。
這是一個非常靈活的解決方案,您可以擴展此示例,使其在需要時從配置文件中讀取緩存持續時間。
優點:
缺點:
解決方案:使用cron作業生成sitemap.xml
。
盡管最終決定在很大程度上取決於項目的特定細節,但總的來說,我還是會堅持第一種方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.