Home > Backend Development > PHP Tutorial > Introduction to pseudo-static configuration methods in various PHP environments (code)

Introduction to pseudo-static configuration methods in various PHP environments (code)

不言
Release: 2023-04-05 15:26:02
forward
2786 people have browsed it

本篇文章给大家带来的内容是关于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>
Copy after login

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

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

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;
      }
}
Copy after login

重启nginx即可生效

三、IIS的伪静态配置

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

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

在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>
Copy after login

The above is the detailed content of Introduction to pseudo-static configuration methods in various PHP environments (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template