由于各个Web服务器使用的地址重写规则语法不同,这里列出常见的几种Web服务器适用的重写规则。

Apache

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

Nginx

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

IIS

 <!--web.config url rewrite-->
 <configuration> 
 <system.webServer>
 <rewrite>
 <rules>
 <rule name="Main Rule" 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:1}" />
  </rule>
  </rules>
  </rewrite>
  </system.webServer>
  </configuration>

Caddy(未验证)

try_files {path} {path}/ /index.php/{path}/?{query}