codeigniter 去除index.php (nginx,apache) 通用方法


.htaccess文件配置

復制代碼
1 <IfModule mod_rewrite.c>
2   RewriteEngine On
3   RewriteBase /
4   RewriteCond $1 !^(index\.php|assets|system|robots\.txt)  
5   RewriteRule ^(.*)$ /index.php/$1 [L,QSA]   
6 
7 </IfModule>
復制代碼

簡要說明:關鍵是這句:rewirteCond ,assets是目錄。

apache的配置:

復制代碼
 1 <VirtualHost *:80>
 2     ServerAdmin jjj@163.com
 3     DocumentRoot "d:/mywork/m"
 4     
 5     ServerName m.mimi.com
 6     
 7     <Directory "d:/mywork/m">    // 這里是項目的目錄
 8         Options Indexes MultiViews FollowSymLinks 
 9         AllowOverride All
10         Order allow,deny
11         allow from all
12    </Directory>
13 </VirtualHost>
復制代碼

簡要說明:

ServerAdmin表示錯誤信息地址,如果發生錯誤發送到這個郵箱地址。

Indexes 的作用就是當該目錄下沒有 index.html 文件時,就顯示目錄結構,去掉 Indexes,Apache 就不會顯示該目錄的列表了。

Nginx配置幾句

復制代碼
1 location /
2         {
3             index index.php;
4             if (!-e $request_filename) {
5                     rewrite ^/(.*)$ /index.php?$1 last;
6                     break;
7             }
8         }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM