URL 重写

可以通过 URL 重写隐藏应用的入口文件 index.php,下面是相关服务器的配置参考:

更多使用方法,请访问手册

[ Nginx ]

  1. 在 nginx 虚拟主机 location 配置中添加规则,规则如下:

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

[ Apache ]

httpd.conf 配置文件中加载了 mod_rewrite.so 模块

AllowOverride None 将 None 改为 All

把下面的内容保存为.htaccess 文件放到应用入口文件的同级目录下

  1.     Options +FollowSymlinks -MultiviewsRewriteEngine on
  2.     RewriteCond %{REQUEST_FILENAME} !-d
  3.     RewriteCond %{REQUEST_FILENAME} !-f
  4.     RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

[ IIS ]

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

  1. RewriteRule (.*)$ /index\.php\?s=$1 [I]
在 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>