~~~
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
~~~
**1、**排除一些條件,必須兩個條件都滿足后才重定向到index.php
//如果你訪問的文件`不等于目錄`
~~~
RewriteCond %{REQUEST_FILENAME} !-d
~~~
//如果你訪問不是文件,比如你可能訪問的JPEG等圖片文件
~~~
RewriteCond %{REQUEST_FILENAME} !-f
~~~
**2、**`^(.*)$`?匹配所有的路徑映射到入口文件?`index.php/$1`
**3、**標簽?`[QSA,PT,L]`?QSA:表示保留參數如get傳值?xxx==xx...; PT:再把這個URL交給Apache處理;L:作為最后一條;
PT和L可加可不加。

* [2017年05月13日更新](https://segmentfault.com/q/1010000009402187/a-1020000009403042)
* 評論
* 贊賞
* 編輯