配置webserver使用静态url功能

2018-03-21 18:10:00    王春生    49821

蝉知系统支持两种访问方式,一种是传统的get方式,比如/?m=article&id=123,代表文章模块的123这篇文章。还有一种是静态url访问,比如/article-view-123.html。

从1.5版本开始,蝉知系统内置了对搜索引擎特别友好的url路径结构。上述的静态url地址会转变成article/123.html。如果123这篇文章所属的类目还设置了类目的别名,比如news,地址还会进一步优化为news/123.html。

但是要想使用静态url方式,需要配置webserver使用静态url功能。如果您使用的是网站空间,一般都已经打开了。如果是自己部署的服务器,请按照下面的来设置:

apache:

1. 配置apache的配置文件,加载 mod_rewrite模块。

2. 为chanzhieps/www目录下面的.htaccess增加权限,例如 修改apache配置文件中的配置改成如下配置( 需要把具体的蝉知目录替换 /home/chanzhieps/www):

<Directory /home/chanzhieps/www>
        Options FollowSymLinks Indexes
        AllowOverride All
    </Directory>


nginx:

location /
{
    try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$
{
    fastcgi_pass  unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $request_uri;
    include modules-enabled/fastcgi.conf;
}


如果是已经开始使用的蝉知系统配置静态url功能,确保以上配置成功后重新安装蝉知系统或修改chanzhi/system/config/my.php内requestType值为PATH_INFO(5.2+版本需要安装成功后进入后台--设置--站点设置,5.4+版本在后台--设置--站点--系统设置, 切换url模式)。


宝塔面板nginx环境:

1. 登录宝塔,点击站点设置;

2. 进入配置,点击配置文件,将配置信息复制进人文本框;复制之后,点击保存。

server
{
    listen 80;
    server_name www.abc.cn;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/www.abc.cn;  # 需要根据具体路径填写
    
    location / 
    {
	try_files $uri $uri/ /index.php?$args;
    }
    
    location ~ \.php$ 
    {
    	try_files $uri =404;
    	fastcgi_pass  unix:/tmp/php-cgi-70.sock;  #根据实际启动的php版本选择
    	fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $request_uri;
    	include /www/server/nginx/conf/fastcgi.conf;  # 需要根据具体路径填写
    }
}

3. 重启nginx或者重载nginx配置

4. 访问蝉知,确认PATH_INFO可以正常访问吗?

后台开启PATH_INFO



浙ICP备14025715号-9
ZSITE8.6