标签 "伪静态" 下的文章

修改实现方法:PHPCMS V9 自定义栏目伪静态实现方法

栏目页伪静态(不生成HTML)时,URL规则中{$categorydir}{$catdir}仍显示为{$categorydir}{$catdir}解决方法。

第一步:打开phpcms\modules\content\classes\url.class.php;

第二步:将122行

$url = str_replace(array('{$catid}', '{$page}'), array($catid, $page), $urlrule);

替换为

$category_dir = $this->get_categorydir($catid);
$url = str_replace(array('{$catid}', '{$page}','{$catdir}','{$categorydir}'), array($catid, $page,$category['catdir'],$category_dir), $urlrule);

第三步:保存
使用须知:
1.更改前请先备份原文件;官方升级如果升级此文件,需要再次修改;
2.{$categorydir}后默认有'/',{$catdir}后默认无 '/'

3.案例:

URL示例:guolei/index.html|guolei/list-2.html
URL规则:{$catdir}/index.html|{$catdir}/list-{$page}.html

伪静态规则:

RewriteRule ^guonei(/|/index.html)$ index.php?m=content&c=index&a=lists&catid=6
RewriteRule ^guonei/list-([0-9]+).html$ index.php?m=content&c=index&a=lists&catid=6&page=$1

4.如有不足之处,请在下方回复说明。

phpcmsV9栏目伪静态的修改方法(支持自定义目录名),官方程序默认伪静态是不支持自定义栏目名的,所以今天就做了以下修改,让其支持!

首先看urlrewrite的规则,这个是Apache下的,其它环境下的规则自己转换下

RewriteRule ^(.*)(.*)/$ /index.php?m=content&c=index&a=lists&catdir=$1
RewriteRule ^(.*)(.*)/index([0-9]+).html$ /index.php?m=content&c=index&a=lists&categorydir=$1&catdir=$2&page=$3

1、打开phpcms\modules\content目录下的index.php找到 public function lists() {,将$catid = intval($_GET['catid']);替换成:

if(isset ($_GET['catid'])){   
                    $catid = intval($_GET['catid']);   
                }else{   
                    $catdir=$_GET['catdir'];   
                    if($catdir==""){   
                        $catdir=$_GET['categorydir'];   
                    }   
                    $s=$this->_getCategoryId($catdir);   
                    $catid=$s[0][catid];                      
                }

并且在最后的 }?> 添加:

/**           *根据栏目名获得ID           
* @param <type> $catdir           */  
        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;   
         }

2、打开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;

3、后台URL规则中添加:

url示例:1/
url规则:/{$categorydir}/{$catdir}/|/{$categorydir}/{$catdir}/index{$page}.html

更新栏目缓存就OK了。

Nginx设置301重定向相对还是比较容易的,301永久重定向不仅能使页面实现自动跳转,而且对于搜索引擎来说,可以传递网站权重、收录以及PR值等。下面我们就详细说说Linux下Nginx设置301重定向的方法:

首先将多个域名指向同一web目录,代码如下:

server_name www.piaoyun.cc piaoyun.cc;

二、我们说下Nginx设置域名301重定向中常用的2种方法:

第一种方法是判断nginx核心变量host(老版本是http_host),适用于绑定多个域名,都相同用途的重定向:

server {
server_name www.piaoyun.cc piaoyun.cc;
if ($host != 'piaoyun.cc' ) {
rewrite ^/(.*)$ http://piaoyun.cc/$1 permanent;
}
...
}

第二种方法,适用于多个域名,但有域名有其他用途不需要重定向的情况:

server {
server_name www.piaoyun.cc piaoyun.cc download.piaoyun.cc;
if ($host = 'www.piaoyun.cc' ) {
rewrite ^/(.*)$ http://piaoyun.cc/$1 permanent;
}
...
}

上面的download.piaoyun.cc为频道域名,不需要重定向。

这两种方法中, permanent是关键,详细见下面nginx重定向规则说明。
last – 基本上都用这个Flag。
break – 中止Rewirte,不在继续匹配
redirect – 返回临时重定向的HTTP状态302
permanent – 返回永久重定向的HTTP状态301

三、测试是否定向成功
SSH中输入指令:

/usr/local/nginx/sbin/nginx -t

提示:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

测试成功后,重启nginx,输入下面指令:

/usr/local/nginx/sbin/nginx -s reload

重启之后测试一下~是否成功设定完成! 输入指令~

下面另外说下Nginx设置目录如何重定向到目录的方法

例如下面这段设定nginx将某个目录下面的文件重定向到另一个目录,$2对应第二个括号(.*)中对应的字符串:

location /download/ {
rewrite ^(/download/.*)/m/(.*)\..*$ $1/nginx-rewrite/$2.gz break;
}

nginx重定向的IF条件判断
在server和location两种情况下可以使用nginx的IF条件判断,条件可以为以下几种:

1、匹配判断:
~ 为区分大小写匹配; !~为区分大小写不匹配
~* 为不区分大小写匹配;!~为不区分大小写不匹配

例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下:

if ($http_user_agent ~ MSIE) {
rewrite ^(.*)$ /nginx-ie/$1 break;
}

2、文件和目录判断
-f和!-f判断是否存在文件
-d和!-d判断是否存在目录
-e和!-e判断是否存在文件或目录
-x和!-x判断文件是否可执行

例如下面设定nginx在文件和目录不存在的时候重定向:

if (!-e $request_filename) {
proxy_pass http://127.0.0.1;
}
return

最近更换了lnmp环境,发现用自带的ecshop.conf的伪静态规则是无效的,不知道是我的设置有问题呢,还是其他问题,通过搜索找到了一个可以用的

正确的可以使用的规则如下:

location / {
    if (!-e $request_filename) {
        rewrite "^/index\.html" /index.php last;
        rewrite "^/category$" /index.php last;
        rewrite "^/feed-c([0-9]+)\.xml$" /feed.php?cat=$1 last;
        rewrite "^/feed-b([0-9]+)\.xml$" /feed.php?brand=$1 last;
        rewrite "^/feed\.xml$" /feed.php last;
        rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last;
        rewrite "^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$" /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last;
        rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;
        rewrite "^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2&page=$3 last;
        rewrite "^/category-([0-9]+)-b([0-9]+)(.*)\.html$" /category.php?id=$1&brand=$2 last;
        rewrite "^/category-([0-9]+)(.*)\.html$" /category.php?id=$1 last;
        rewrite "^/goods-([0-9]+)(.*)\.html" /goods.php?id=$1 last;
        rewrite "^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;
        rewrite "^/article_cat-([0-9]+)-([0-9]+)(.*)\.html$" /article_cat.php?id=$1&page=$2 last;
        rewrite "^/article_cat-([0-9]+)(.*)\.html$" /article_cat.php?id=$1 last;
        rewrite "^/article-([0-9]+)(.*)\.html$" /article.php?id=$1 last;
        rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html" /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last;
        rewrite "^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2&page=$3 last;
        rewrite "^/brand-([0-9]+)-c([0-9]+)(.*)\.html" /brand.php?id=$1&cat=$2 last;
        rewrite "^/brand-([0-9]+)(.*)\.html" /brand.php?id=$1 last;
        rewrite "^/tag-(.*)\.html" /search.php?keywords=$1 last;
        rewrite "^/snatch-([0-9]+)\.html$" /snatch.php?id=$1 last;
        rewrite "^/group_buy-([0-9]+)\.html$" /group_buy.php?act=view&id=$1 last;
        rewrite "^/auction-([0-9]+)\.html$" /auction.php?act=view&id=$1 last;
        rewrite "^/exchange-id([0-9]+)(.*)\.html$" /exchange.php?id=$1&act=view last;
        rewrite "^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last;
        rewrite "^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;
        rewrite "^/exchange-([0-9]+)-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1&page=$2 last;
        rewrite "^/exchange-([0-9]+)(.*)\.html$" /exchange.php?cat_id=$1 last;
    }

    if (!-e $request_filename) {
        return 404;
    }
}

lnmp自带的规则如下(我使用无效):

if (!-e $request_filename)
{
rewrite "^/index\.html" /index.php last;
rewrite "^/category$" /index.php last;
rewrite "^/feed-c([0-9]+)\.xml$” /feed.php?cat=$1 last;
rewrite “^/feed-b([0-9]+)\.xml$” /feed.php?brand=$1 last;
rewrite “^/feed\.xml$” /feed.php last;
rewrite “^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$” /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5&page=$6&sort=$7&order=$8 last;
rewrite “^/category-([0-9]+)-b([0-9]+)-min([0-9]+)-max([0-9]+)-attr([^-]*)(.*)\.html$” /category.php?id=$1&brand=$2&price_min=$3&price_max=$4&filter_attr=$5 last;
rewrite “^/category-([0-9]+)-b([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$” /category.php?id=$1&brand=$2&page=$3&sort=$4&order=$5 last;
rewrite “^/category-([0-9]+)-b([0-9]+)-([0-9]+)(.*)\.html$” /category.php?id=$1&brand=$2&page=$3 last;
rewrite “^/category-([0-9]+)-b([0-9]+)(.*)\.html$” /category.php?id=$1&brand=$2 last;
rewrite “^/category-([0-9]+)(.*)\.html$” /category.php?id=$1 last;
rewrite “^/goods-([0-9]+)(.*)\.html” /goods.php?id=$1 last;
rewrite “^/article_cat-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$” /article_cat.php?id=$1&page=$2&sort=$3&order=$4 last;
rewrite “^/article_cat-([0-9]+)-([0-9]+)(.*)\.html$” /article_cat.php?id=$1&page=$2 last;
rewrite “^/article_cat-([0-9]+)(.*)\.html$” /article_cat.php?id=$1 last;
rewrite “^/article-([0-9]+)(.*)\.html$” /article.php?id=$1 last;
rewrite “^/brand-([0-9]+)-c([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)\.html” /brand.php?id=$1&cat=$2&page=$3&sort=$4&order=$5 last;
rewrite “^/brand-([0-9]+)-c([0-9]+)-([0-9]+)(.*)\.html” /brand.php?id=$1&cat=$2&page=$3 last;
rewrite “^/brand-([0-9]+)-c([0-9]+)(.*)\.html” /brand.php?id=$1&cat=$2 last;
rewrite “^/brand-([0-9]+)(.*)\.html” /brand.php?id=$1 last;
rewrite “^/tag-(.*)\.html” /search.php?keywords=$1 last;
rewrite “^/snatch-([0-9]+)\.html$” /snatch.php?id=$1 last;
rewrite “^/group_buy-([0-9]+)\.html$” /group_buy.php?act=view&id=$1 last;
rewrite “^/auction-([0-9]+)\.html$” /auction.php?act=view&id=$1 last;
rewrite “^/exchange-id([0-9]+)(.*)\.html$” /exchange.php?id=$1&act=view last;
rewrite “^/exchange-([0-9]+)-min([0-9]+)-max([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$” /exchange.php?cat_id=$1&integral_min=$2&integral_max=$3&page=$4&sort=$5&order=$6 last;
rewrite ^/exchange-([0-9]+)-([0-9]+)-(.+)-([a-zA-Z]+)(.*)\.html$” /exchange.php?cat_id=$1&page=$2&sort=$3&order=$4 last;
rewrite “^/exchange-([0-9]+)-([0-9]+)(.*)\.html$” /exchange.php?cat_id=$1&page=$2 last;
rewrite “^/exchange-([0-9]+)(.*)\.html$” /exchange.php?cat_id=$1 last;
}