齐博x1第一季《新手入门》系列014-伪静态的相关设置

2019-07-09 作者:torylf 分类:教程 阅读:2009

X1因为是基于thinkphp开发的,所以伪静态的设置就是thinkphp的设置


其实我们这里X1设置伪静态也就是为了隐藏index.php而设置,其他的url美化路径,修改后缀如html等都是通过路由来设置了

伪静态配置好后,这里才可以设置,否则网站打开会出现错误,或者永远是首页


不同的web服务器设置不同,以下列举常用的搭配设置,其他的略去不提

我们常用的web服务器:Apache、IIS、nginx三种,应该是目前最多的

一般就是这几种搭配 linux+apache 、linux+nginx、win+iis、win+apache 

win+nginx都很少了。

linux+apache环境,直接设置.htaccess, 用thinkphp官方提供的默认即可,如下:

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

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


win+apache环境  比如phpstudy这种套件配置的环境也是设置.htaccess但是有些特别,如果是全新安装,那就不用配置,直接使用x1里默认的即可

<IfModule mod_rewrite.c>
  Options +FollowSymlinks -Multiviews
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>


Linux+Nginx环境 也是直接用thinkphp官方提供的配置即可,nginx是在站点的conf里配置,如果是虚拟主机,在vhost中配置xxx.conf然后include xxx.conf,当然写入到具体站点的conf里也是可以的

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


Win+IIS环境  IIS可能有些人觉得是最麻烦的,其实直接复制代码也很简单,IIS7.5以上配置web.config即可。当然前提是服务器需要安装url_rewrite

web.config如果没有其他配置,直接复制下面完整的代码到web.config就可以了,如果web.config有其他的配置,需要注意rules的嵌套。IIS7以下的环境就忽略了,建议升级系统吧。

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






来源: 神盾工作室    转载请注明出处!

本文地址:https://www.shieldsoho.com/article/15.html

{{item.nickname}} @回复
发表于{{item.create_time}}

  • {{replyitem.nickname}} {{item.create_time}}
    @{{item.nickname}}

查看更多评论