AVS3.0 程序分析1

一、关于Rewrite的分析

    AVS默认推荐使用Apache环境运行,因为程序中自带.htaccess文件,内容如下:

#如果服务器报500错误注释这2行
Options -Indexes
Options +FollowSymLinks

#反注释下面几行,如果你想使用图片缓存
#<IfModule mod_expires.c>
#  ExpiresActive On
#  ExpiresDefault A1209600
#  ExpiresByType text/html A1
#</IfModule>

# Uncomment following lines if Apache doesnt support MultiViews!
<IfModule mod_rewrite.c>
    RewriteEngine On

        # Uncomment the 2 lines below if you are using www.domain.com
        # as the baseurl for the site and users access your site
        # via domain.com (THIS IS REQUIRED FOR JQUERY TO WORK)
        #如果访问的不带www的域名则跳转到带www的域名
        #e.g.: baidu.com => www.baidu.com
        RewriteCond %{HTTP_HOST} ^domain.com [NC]
        RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

    RewriteCond %{REQUEST_FILENAME} !-f  #如果请求的不是文件
    RewriteCond %{REQUEST_FILENAME} !-d  #如果请求的不是目录
    RewriteRule .* loader.php [L,QSA]    #重写到loader.php处理请求
</IfModule>


对应的Nginx规则:

	location / 
	{
		#-f 判断是否文件
		#-d 判断是否目录
		#-e 判断是否文件或目录
		if (!-e $request_filename){
			rewrite ^(.*)$ /loader.php last;
		}
	}


其中,last最为关键,之前调试的时候设为break,怎么都不行,百斯不得骑姐:)后来百度才明白这二者的区别

如果配置中存在N多个location,last匹配后还会继续循环匹配,而break则立即终止匹配。

参考文章:Nginx Rewrite研究笔记 nginx中的break与last指令区别

<?php
//die('Only enable this script if you dont have support for MultiViews');
$relative = '';
$loaders  = array(
    'ajax' => 1,
    'album' => 1,
    'albums' => 1,
    'blog' => 1,
    'blogs' => 1,
    'captcha' => 1,
    'categories' => 1,
    'community' => 1,
    'confirm' => 1,
    'error' => 1,
    'feedback' => 1,
    'feeds' => 1,
    'game' => 1,
    'games' => 1,
    'index' => 1,
    'invite' => 1,
    'loader' => 1,
    'login' => 1,
    'logout' => 1,
    'lost' => 1,
    'mail' => 1,
    'notice' => 1,
    'notices' => 1,
    'photo' => 1,
    'requests' => 1,
    'search' => 1,
    'signup' => 1,
    'static' => 1,
    'stream' => 1,
    'upload' => 1,
    'user' => 1,
    'users' => 1,
    'video' => 1,
    'videos' => 1,
    'edit' => 1
);
$query      = ( isset($_SERVER['QUERY_STRING']) ) ? $_SERVER['QUERY_STRING'] : NULL;
$request    = str_replace($relative, '', $_SERVER['REQUEST_URI']);
$request    = str_replace('?' .$query, '', $request);
$request    = explode('/', trim($request, '/'));
if (isset($request['0'])) {
    $page   = $request['0'];
    if (isset($loaders[$page])) {
        require $page. '.php';
    } else {
		header('HTTP/1.0 404 Not Found');
  		die();
	}
} else {
	header('HTTP/1.0 404 Not Found');
    die();
}

这段代码就是检测/xxx允许访问的页面,然后访问对应的.php

eg: http://www.xxx.com/video实际上访问的是/video.php


补充:AVS默认调用的是googleapis,国内你懂的……

进入templates目录,执行下面命令替换成360源或新浪源

sed -i 's#https://ajax.googleapis.com#http://ajax.useso.com#g' `find . -name '*.tpl'`
sed -i 's#https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js#http://lib.sinaapp.com/js/jquery/1.8.3/jquery.min.js#g' `find -L -name '*.tpl'`

去掉addthis

sed -i 's*<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=avsbookmark"></script>**g' `find .  -name *.tpl`


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值