2014年4月13日 星期日

去除掉 index.php

每當瀏覽網頁 URL 都有個 index.php 包在裡面,實在是很醜

在網路上找了很多資料,終於把它給用掉... 嘿!漂亮多了~~



[Step 1] 確定 Apache 的 mod_rewrite 是否有開啟

            apache\conf\httpd.conf

            搜尋

            #LoadModule rewrite_module modules/mod_rewrite.so

            把它 反註解掉
  
        =>LoadModule rewrite_module modules/mod_rewrite.so


[Step 2] 修改 Codeigniter 的 config

             application\config\config.php

             $config['index_page'] = 'index.php';


        =>$config['index_page'] = '';

[Step 3] 新增 .htaccess

建立在 專案名稱的根目錄下

.htaccess的內容

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]

[Step 4] 重開 Apache

資料來源

沒有留言 :

張貼留言