首页 > 运营 > 建站经验 > 正文

浅谈PHP各环境下的伪静态配置

2021-11-26 12:51:16
字体:
来源:转载
供稿:网友

这篇文章主要介绍了PHP各环境下的伪静态配置,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。

一、Apache的伪静态配置

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

  1. <IfModule mod_rewrite.c> 
  2. RewriteEngine on 
  3. RewriteCond %{REQUEST_FILENAME} !-d 
  4. RewriteCond %{REQUEST_FILENAME} !-f 
  5. RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 
  6. </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{ } 里增加以下内容

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

重启nginx即可生效

三、IIS的伪静态配置

如果你的服务器环境支持ISAPI_Rewrite的话,可以配置httpd.ini文件,添加下面的内容:

RewriteRule (.*)$ /index/.php/?s=$1 [I]

在IIS的高版本下面可以配置web.Config,在中间添加rewrite节点:

  1. <rewrite> 
  2. <rules> 
  3. <rule name="OrgPage" stopProcessing="true"> 
  4. <match url="^(.*)$" /> 
  5. <conditions logicalGrouping="MatchAll"> 
  6. <add input="{HTTP_HOST}" pattern="^(.*)$" /> 
  7. <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
  8. <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
  9. </conditions> 
  10. <action type="Rewrite" url="index.php/{R:1}" /> 
  11. </rule> 
  12. </rules> 
  13. </rewrite>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表