phpcms v9 欄目偽靜態完全自定義為欄目英文目錄名
1,後臺增加url規則,增加後.導航上,或分頁號上,會自動替換為靜態的樣式.類似www.abc.com/news/2/ 2表示頁碼
phpcms v9 的後臺擴充套件,url規則,新增兩個規則,
一個是名稱為category的規則,規則的前面的斜線可以去掉,不過可能影響分頁問題
/{$catdir}/|/{$catdir}/{$page}/
url示例為 www.abc.com/news/
一個是名稱為show規則
{$catdir}/{$id}.html|{$catdir}/{$id}_{$page}.html
示例為www.abc.com/news/99.html
然後,找到想偽靜態的欄目,修改.生成html設定,生成Html全設定為否,url規則選擇自己剛才設定的.儲存,
最後更新欄目快取及批量更新url,不更新無效
2,如果為apache的伺服器空間,偽靜態規則如下,注意,要儲存在.htaccess 檔案中,並上傳到網站根目錄中,其它規則自己轉換
RewriteEngine on
#靜態檔案以及API目錄不需要偽靜態
RewriteRule ^(statics|api|uploadfile)(.*) - [L]
#欄目頁
RewriteRule ^([0-9A-Za-z_]*)$ index.php?m=content&c=index&a=lists&catdir=$1
RewriteRule ^([0-9A-Za-z_]*)/$ index.php?m=content&c=index&a=lists&catdir=$1
RewriteRule ^([0-9A-Za-z_]*)/([0-9]+)$ index.php?m=content&c=index&a=lists&catdir=$1&page=$2
RewriteRule ^([0-9A-Za-z_]*)/([0-9]+)/$ index.php?m=content&c=index&a=lists&catdir=$1&page=$2
#上面欄目分頁,是完全的字母加數字的形式,如www.abc.com/news/2 ,後面不帶其它字元,或加一個/字元,如果伺服器偽靜態匹配到了"域名/字母/數字/"的組合,則會自動跳轉到index.php?m=content&c=index&a=lists&catdir=$1&page=$2這個頁面中.所以.前面的規則不可重複,否則會錯亂.
#內容頁
RewriteRule ^([0-9A-Za-z_]*)/([0-9]+)\.html$ index.php?m=content&c=index&a=show&catdir=$1&id=$2
3,檔案,phpcms\phpcms\modules\content\index.php中
搜尋
$catid = intval($_GET['catid']);
一共兩處,修改為
if(isset ($_GET['catid'])){
$catid = intval($_GET['catid']);
}else{
$catdir=$_GET['catdir'];
$s=$this->_getCategoryId($catdir);
$catid=$s[0][catid];
}
然後,在最下面
} 這個 大括號的前面增加一個函式,如下
protected function _getCategoryId($catdir){
$this->category_db = pc_base::load_model('category_model');
$result = $this->category_db->select(array('catdir'=>$catdir));
// print_r($result);
return $result;
}
4, 開啟phpcms\modules\content\classes\url.class.php,找到
if (!$setting['ishtml']) { //如果不生成靜態
將下面的:
$url = str_replace(array('{$catid}', '{$page}'), array($catid, $page), $urlrule);
if (strpos($urls, '\\')!==false) {
$url = APP_PATH.str_replace('\\', '/', $urls);
}
整體替換為
$domain_dir = '';
if (strpos($category['url'], '://')!==false && strpos($category['url'], '?')===false) {
if (preg_match('/^((http|https):\/\/)?([^\/]+)/i', $category['url'], $matches)) {
$match_url = $matches[0];
$url = $match_url.'/';
}
$db = pc_base::load_model('category_model');
$r = $db->get_one(array('url'=>$url), '`catid`');
if($r) $domain_dir = $this->get_categorydir($r['catid']).$this->categorys[$r['catid']]['catdir'].'/';
}
$categorydir = $this->get_categorydir($catid);
$catdir = $category['catdir'];
$year = date('Y',$time);
$month = date('m',$time);
$day = date('d',$time);
//echo $catdir;
$urls = str_replace(array('{$categorydir}','{$catdir}','{$year}','{$month}','{$day}','{$catid}','{$id}','{$prefix}','{$page}'),array($categorydir,$catdir,$year,$month,$day,$catid,$id,$prefix,$page),$urlrule);
// echo $urls."<br>";
if (strpos($urls, '\\')!==false) {
$urls = APP_PATH.str_replace('\\', '/', $urls);
}
$url = $domain_dir.$urls;
參考源 http://blog.ganhui0818.cn/article/335.htm
相關文章
- phpcms當前欄目呼叫父級及以下欄目資訊方法PHP
- 自定義目錄
- Ubuntu更改主目錄檔名為英文Ubuntu
- Ubuntu 16.04切換/home中文目錄為英文目錄Ubuntu
- SIS(Sales Information System)步驟1-維護自定義欄位目錄ORM
- Ubuntu 16.04修改Home目錄下的中文目錄為英文Ubuntu
- Laravel 中自定義日誌目錄Laravel
- Zblog Nginx 下二級目錄設定偽靜態程式碼Nginx
- PhpCms自定義欄位的使用說明PHP
- dedecms二級欄目分類使用channelartlist標籤實現當前欄目高亮
- Java ArrayList操作英文書目錄Java
- 【目錄】JVM目錄JVM
- Apache 新增自定義vhost 目錄,等其他配置Apache
- 【目錄】集合框架目錄框架
- 關於《隨筆》這個欄目
- 【目錄】JUC鎖框架目錄框架
- oracle GlodenGate 建立目錄下每個目錄的含義Oracle
- 虛幻5渲染程式設計專欄概述及目錄程式設計
- [提問交流]當程式不在根目錄的時候怎麼設定偽靜態
- 網站二級目錄或者子目錄安裝WordPress偽靜態規則設定方法,伺服器為nginx網站伺服器Nginx
- Directory類提供的靜態方法去處理目錄
- gitignore 忽略目錄下檔案僅保留目錄形態Git
- CIO時代APP正式推出教師欄目APP
- 網站欄目和頁面的策劃網站
- Jboss下將某個應用目錄配置為根目錄
- 目錄:SpringBoot學習目錄Spring Boot
- grep -r “字串” 目錄名的使用字串
- 【Linux中國】“書庫”欄目正式上線!Linux
- 欄目總導航—MXCMSSiteNavi標籤說明
- Git學習2:為什麼工作區目錄下有.git目錄Git
- Nginx虛擬目錄alias和root目錄Nginx
- /opt目錄和/usr目錄的區別
- Nginx同一個server部署多個靜態資源目錄NginxServer
- 瘋狂android講義目錄Android
- 【機器學習】目錄機器學習
- ORACLE目錄Oracle
- 活動目錄
- 目錄操作