Discussion on Pseudo static Configuration of PHP in Various Environments

  • 2021-11-29 23:20:05
  • OfStack

1. Pseudo static configuration of Apache

1. The root directory of the website needs to have. htaccess file. If there is no one, create one by yourself. The content


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

If your apache is in fastcgi mode, it needs to be modified


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

2. Look in the configuration file httpd. conf of apache: LoadModule rewrite_module modules/mod_rewrite. so Remove the preceding #. If there is no such content, you need to add it manually

3. Find all AllowOverride None in apache configuration file httpd. conf, replace None with All, save the file and restart apache service.

2. Pseudo static configuration of Nginx

Find the configuration file nginx. conf for nginx and add the following in server {}


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

Restart nginx to take effect

3. Pseudo static configuration of IIS

If your server environment supports ISAPI_Rewrite, configure the httpd. ini file and add the following:


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

Under the higher version of IIS, you can configure web. Config, adding the rewrite node in the middle:


<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>

Related articles: