分类 学习笔记 下的文章

网站有时候有多个域名,所以需要做跳转
有时候也需要顶级直接跳转到www上,现就记录nginx跳转实例。

server  
    {  
        listen       80;  
        server_name www.1.com www.22.com.cn www.333.com;  
        index index.html index.htm index.php;  
        root /home/www;  
  
        if ($host = 'www.22.com.cn' ) {  
                rewrite ^/(.*)$ http://www.1.com/$1 permanent;  
        }  
        if ($host = '333.com' ) {  
                rewrite ^/(.*)$ http://www.1.com/$1 permanent;  
        }  
        if ($host = '22.com.cn' ) {  
                rewrite ^/(.*)$ http://www.1.com/$1 permanent;  
        }  

break 中止Rewirte,不在继续匹配;
redirect 为302临时重定向的HTTP状态;
permanent 为301永久重定向的HTTP状态。

在网站部署中,考虑网站的安全行问题,可以将您的网站主程序与WEB目录分离,使主程序在WEB目录之外,从而提高网站的安全性。

分离方法
1.将PHPCMS V9中程序主框架目录phpcms移动至web目录之外
如图:
11
2.修改web目录下程序入口文件index.php文件为

/**
 *  index.php PHPCMS 入口
 *
 * @copyright           (C) 2005-2010 PHPCMS
 * @license             http://www.phpcms.cn/license/
 * @lastmodify          2010-6-1
 */
 //PHPCMS根目录
define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
include '../phpcms/base.php';
pc_base::creat_app();

3.修改web目录下接口文件文件api.php文件为

/**
 *  index.php API 入口
 *
 * @copyright           (C) 2005-2010 PHPCMS
 * @license             http://www.phpcms.cn/license/
 * @lastmodify          2010-7-26
 */
define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
include '../phpcms/base.php';
$param = pc_base::load_sys_class('param');
 
$op = isset($_GET['op']) && trim($_GET['op']) ? trim($_GET['op']) : exit('Operation can not be empty');
if (!preg_match('/([^a-z_]+)/i',$op) && file_exists(PHPCMS_PATH.'api/'.$op.'.php')) {
    include PHPCMS_PATH.'api/'.$op.'.php';
} else {
    exit('API handler does not exist');
}

这样即可以完成主程序与web目录分离

在modules/content/content.php 的public_categorys方法里1027行左右,把

if (!empty($categorys)) {

}

里面的代码改为以下的:

$tree->init($categorys);
            switch ($from) {
                case 'block':
                    $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=block&c=block_admin&a=public_visualization&menuid=" . $_GET['menuid'] . "&catid=\$catid&type=list' target='right'>\$catname</a> \$vs_show</span>";
                    $strs2 = "<img src='" . IMG_PATH . "folder.gif'> <a href='?m=block&c=block_admin&a=public_visualization&menuid=" . $_GET['menuid'] . "&catid=\$catid&type=category' target='right'>\$catname</a>";
                    break;

                default:
                    $strs = "<span class='\$icon_type'>\$add_icon<a href='?m=content&c=content&a=\$type&menuid=" . $_GET['menuid'] . "&catid=\$catid' target='right' onclick='open_list(this)'>\$catname</a></span>";
                    $strs2 = "<span class='folder'><a href='?m=content&c=content&a=\$type&menuid=" . $_GET['menuid'] . "&catid=\$catid' target='right' onclick='open_list(this)'>\$catname</a></span>";
                    break;
            }
            $categorys = $tree->get_treeview(0, 'category_tree', $strs, $strs2, $ajax_show);