URL 重写
可以通过 URL 重写隐藏应用的入口文件 index.php,下面是相关服务器的配置参考:
更多使用方法,请访问手册
[ Nginx ]
在 nginx 虚拟主机 location 配置中添加规则,规则如下:
- location / {
- if (!-e $request_filename) {
- rewrite ^(.*)$ /index.php?s=/$1 last; break;
- }
- }
[ Apache ]
httpd.conf 配置文件中加载了 mod_rewrite.so 模块
AllowOverride None 将 None 改为 All
把下面的内容保存为.htaccess 文件放到应用入口文件的同级目录下
- Options +FollowSymlinks -MultiviewsRewriteEngine on
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteRule ^(.*)$ index.php?/$1
[ IIS ]
如果你的服务器环境支持 ISAPI_Rewrite 的话,可以配置 httpd.ini 文件,添加下面的内容:
在 IIS 的高版本下面可以配置 web.Config,在中间添加 rewrite 节点:
- RewriteRule (.*)$ /index\.php\?s=$1
<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>


