Pbootcms设置伪静态规则方法

2022-7-15 16:28

作用:配置程序伪静态后URL中将不再包含index.php,整个地址更美观。
1、IIS7+环境(IIS6的环境自行百度):
1)安装rewrite组件,如果使用空间一般空间商默认已经安装;
2)到后台配置参数中开启伪静态开关;
3)在站点目录建立web.config文件(可到源码包rewrite目录下拷贝规则),规则内容如下:
#1.X版本使用如下规则:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>.
    <system.webServer>
        <rewrite>
            <rules>
                 <rule name="reIndex" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

#2.X+版本使用如下规则:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                 <rule name="reIndex" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="true" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php?p={R:1}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

2、Apache环境
1)开启Apache重写模块,具体请百度,如果使用空间一般空间商默认已经开启;
2)到后台配置参数中开启伪静态开关;
3)在站点目录建立.htaccess文件(可到源码包rewrite目录下拷贝规则),规则内容如下:

#1.X版本使用如下规则:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  
#如果页面出现"No input file specified." 请注释第一条,启用第二条

 RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
 #RewriteRule ^(.*)$ index.php [E=PATH_INFO:$1,QSA,PT,L] 
 </IfModule>

#2.X+版本使用如下规则:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?p=$1 [QSA,PT,L]
  </IfModule>

3、Nginx环境
1)到后台配置参数中开启伪静态;
2)在nginx虚拟主机location配置中添加规则,规则如下:

#1.X版本使用如下规则:

location / {
    if (!-e $request_filename){
        rewrite ^/(.*)$ /index.php/$1 last;
     }
}

#2.X+版本使用如下规则:

location / {
    if (!-e $request_filename){
        rewrite ^/(.*)$ /index.php?p=$1 last;
     }
}

注意:Nginx中如果站点部署在二级目录,请对应修改重写规则, 如:二级目录为test则:

rewrite ^/test/(.*)$ /test/index.php?p=$1 last;

附:nginx开启PHP及pathinfo支持的方法,在server内部添加如下内容:

location ~ .php(.*)$ {undefined
root           D:/wwwroot;    #你的网站目录,注意修改
fastcgi_pass   127.0.0.1:9000;   #php-cgi监听地址
fastcgi_index  index.php;    #默认页
fastcgi_split_path_info ^(.+.php)(.*)$;    #分离路径
fastcgi_param PATH_INFO       $fastcgi_path_info;  #添加PATH_INFO信息
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}

备注:本文作者为CSDN博主「站鸟网」

Copyright © 2002-2024 Iszw.net All Rights Reserved.      川公网安备 51010702002244号

蜀ICP备2020035322号-1    本站已开启 IPv6 访问

返回顶部