伪静态

燃烧的冰2018-10-24  12.9K+

ftp进入conf目录

下载conf.php文件

使用notepad++打开,所有支持utf8的编辑器都可以。

 

需要编辑 conf/conf.php

1. 编辑 'url_rewrite_on'=>1,

wellcms 支持 4 种格式伪静态:

0:?user-login.html

1:user-login.html

2:/user/login.html

3:/user/login

 

0 和1 格式支持二级目录,需要修改 conf/conf.php 如下

'path' => './',
'cookie_path' => '',

2 和 3 格式不支持二级目录,需要修改 conf/conf.php 如下

'path' => '/',
'cookie_path' => '/',

保存conf.php,然后上传覆盖原文件。

 

2. 清空 tmp 目录里面的文件;

3.设置伪静态规则,重启服务,进入后台清空缓存。

 

Nginx:

打开 nginx 配置文件 /usr/local/nginx/conf/nginx.conf 找到对应的虚拟主机配置处,追加加粗行:

 

 

url_rewrite_on 为 1 格式 user-login.html 伪静态规则:

location / {

    if (!-e $request_filename) {

        rewrite ^((.*)/)?(.*).html$ $1/index.php last;

    }

}

 

url_rewrite_on 为 2格式 /user/login.html 或 3 格式 /user/login/

目录化伪静态 Nginx 伪静态规则,其他环境请自行修改:

location / {

    if (!-e $request_filename) {

      rewrite ^((.*)/) /index.php last;

    }

}

 

如果 filename 存在,则为真 [ -e /var/log/syslog ]-d filename
如果 filename 为目录,则为真 [ -d /tmp/mydir ]-f filename
如果 filename 为常规文件,则为真 [ -f /usr/bin/grep ]-L filename

 

下面这个伪静态同时支持htm和html后缀

location / {

    rewrite ^((.*)/)?(.*).html$ $1/index.php last;

    try_files $uri $uri/ /index.html;

}

 

然后重新启动 nginx: service nginx restart

 

旧站点转移到 wellcms 的站点,只要入库时传入旧链接 ID ,就会对应wellcms ID,那么可以使用以下伪静态301跳转到 wellcms 链接。WellCMS使用的是自增ID形式,可以通过入库接口传入数字ID。

 

1.目录链接 www.x.com/5/

if ($request_uri ~ ^/(\d+)/$) {
        rewrite ^/(\d+)/$ http://www.x.com/read-$1.html permanent;
}

 

2.www.x.com/read_5.html

if ($request_uri ~ ^/read_(\d+).html$) {
        rewrite ^/read_(\d+).html$ http://www.x.com/read-$1.html permanent;
}

 

其他链接形式自行替换即可,只要ID对应就可以。

 

Apache: 

vim /etc/httpd/conf/httpd.conf

<Directory d:/wellcms.com>

    Options FollowSymLinks ExecCGI Indexes

    AllowOverride all

    Order deny,allow

    Allow from all

    Satisfy all

 

NameVirtualHost *:80

 

Apache .htaccess 网友分享伪静态 2 和 3 规则,自行测试修改

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+) index.php?rewrite=$1 [L]
</IfModule>

 

Apache .htaccess 伪静态 1 规则

如果Appache 支持 .htaccess,那么可以编辑 .htaccess 文件放置于根目录下:

 

RewriteEngine on

 

# Apache 2.4

RewriteCond %{REQUEST_FILENAME} !-d 

RewriteCond %{REQUEST_FILENAME} !-f 

RewriteRule ^(.*?)([^/]*)$ $1index.php?$2 [QSA,PT,L]

 

# Apache other

#RewriteRule ^(.*?)([^/]*)\.html(.*)$ $1/index.php?$2.html$3 [L]

 

 

Apache httpd.conf

如果将规则直接放入 httpd.conf 则需要在前面加 / ,看来 Apache 也反人类:

 

RewriteEngine on

RewriteRule ^(.*?)([^/]*)\.html(.*)$ $1/index.php?$2.html$3 [L]

 

 

 SAE环境,根目录建立 config.yaml 文件:

appname: wellcms
version: 1
handle:
- rewrite: if ( !is_dir() && !is_file() && path ~ "admin/(.*.html)" ) goto "admin/index.php?%1"

- rewrite: if ( !is_dir() && !is_file() && path ~ "[^/?].html" ) goto "index.php?%1"

 

iis 7.5移步到这个页面

http://www.wellcms.cn/read-12.html

0