• PHP各环境下的伪静态配置


    一、Apache的伪静态配置

    1、网站根目录下需要有 .htaccess 文件,没有则自己创建一个,内容为

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

    如果你的apache是fastcgi模式下,则需要修改 

    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    替换成
    RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

    2、在apache的配置文件httpd.conf中查找 : LoadModule rewrite_module modules/mod_rewrite.so  将前面的#去掉,假如没有这段内容,则需要手动加上

    3、在apache的配置文件httpd.conf中查找所有的 AllowOverride None,将 None 都替换成 All . 保存文件 并重启apache服务。

     

     

    二、Nginx的伪静态配置

    找到nginx的配置文件 nginx.conf, 在里面的 server{ } 里增加以下内容 

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

    重启nginx即可生效

    三、IIS的伪静态配置

    如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:
    RewriteRule (.*)$ /index.php?s=$1 [I]
    在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:
    <rewrite>
    <rules>
    <rule name="OrgPage" stopProcessing="true">
    <match url="^(.*)$" />
    <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="^(.*)$" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="index.php/{R:1}" />
    </rule>
    </rules>
    </rewrite>

    如果你的apache是fastcgi模式下,则需要修改 

    1
    2
    3
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    替换成
    RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]

    2、在apache的配置文件httpd.conf中查找 : LoadModule rewrite_module modules/mod_rewrite.so  将前面的#去掉,假如没有这段内容,则需要手动加上

    3、在apache的配置文件httpd.conf中查找所有的 AllowOverride None,将 None 都替换成 All . 保存文件 并重启apache服务。

     

    二、Nginx的伪静态配置

    找到nginx的配置文件 nginx.conf, 在里面的 server{ } 里增加以下内容 

    1
    2
    3
    4
    5
    6
    location / {
          if (!-e $request_filename) {
                 rewrite  ^(.*)$  /index.php?s=$1  last; 
                 break;
          }
    }

    重启nginx即可生效

      

    三、IIS的伪静态配置

    如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:
    1
    RewriteRule (.*)$ /index.php?s=$1 [I]
    在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <rewrite>
    <rules>
    <rule name="OrgPage" stopProcessing="true">
    <match url="^(.*)$" />
    <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="^(.*)$" />
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    </conditions>
    <action type="Rewrite" url="index.php/{R:1}" />
    </rule>
    </rules>
    </rewrite>
  • 相关阅读:
    简单探讨spring整合mybatis时sqlSession不需要释放关闭的问题
    男人常做俯卧撑,谁还敢说不行!
    五大穴位
    实战c++中的vector系列--vector的一些异常
    [Canvas画图] 藏图阁(16) 人体穴位
    算法题:剔除字符串(非常有意思)
    怎样在win8系统下建立wifi热点
    【code】flex_进度条样式
    使用bbed改动数据
    Go语言核心之美 3.2-slice切片
  • 原文地址:https://www.cnblogs.com/xiaowie/p/15148165.html
Copyright © 2020-2023  润新知