Home  >  Article  >  Backend Development  >  AVS30 program analysis 1

AVS30 program analysis 1

WBOY
WBOYOriginal
2016-08-08 09:21:001718browse

一、关于Rewrite的分析

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

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

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

# Uncomment following lines if Apache doesnt support MultiViews!

    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处理请求



对应的Nginx规则:

	location / 
	{
		#-f 判断是否文件
		#-d 判断是否目录
		#-e 判断是否文件或目录
		if (!-e $request_filename){
			rewrite ^(.*)$ /loader.php last;
		}
	}
其中,last最为关键,之前调试的时候设为break,怎么都不行,百斯不得骑姐:)后来百度才明白这二者的区别

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

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

 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


版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了AVS30 程序分析1,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn