配置.htaccess以下:php
RewriteEngine on RewriteBase / RewriteCond $1 !^(index\.php|images|robots\.txt|css|js); RewriteRule ^(.*)$ /sis/index.php/$1 [L]
Apache(error.log)報錯以下:css
12220:tid 1848] [client ::1:50815] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3590): [client ::1:50815] AH00121: r->uri = /sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/sis/index.php/sis/index.php/sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/sis/index.php/sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/sis/index.php/news/create [Thu Sep 10 14:24:14.491172 2015] [core:debug] [pid 12220:tid 1848] core.c(3596): [client ::1:50815] AH00122: redirected from r->uri = /sis/index.php/news/create
蒐集到的有用的參考資料:http://www.askapache.com/htaccess/modrewrite-tips-tricks.htmlhtml
Loop Stopping Code ^ Sometimes your rewrites cause infinite loops, stop it with one of these rewrite code snippets. RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|error/).* [NC] RewriteRule .* - [L] RewriteCond %{ENV:REDIRECT_STATUS} 200 RewriteRule .* - [L]
修改後的.htaccessapache
RewriteEngine on RewriteBase / RewriteCond %{ENV:REDIRECT_STATUS} 200 RewriteRule .* - [L] RewriteCond $1 !^(index\.php|images|robots\.txt|css|js); RewriteRule ^(.*)$ /sis/index.php/$1 [L]
問題解決:瀏覽器地址欄中輸入http://localhost/sis/news(不用輸入index.php),頁面打開正常。瀏覽器