我如何使用mod_rewrite我的問題是,當我打開我的網站的管理部分我必須寫www.example.com/index.php/admin更改站點URL Apache中的mod_rewrite與
改變我的網站的網址是什麼我要的是我直接打開我的網站像www.example.com/admin請幫助
感謝
我如何使用mod_rewrite我的問題是,當我打開我的網站的管理部分我必須寫www.example.com/index.php/admin更改站點URL Apache中的mod_rewrite與
改變我的網站的網址是什麼我要的是我直接打開我的網站像www.example.com/admin請幫助
感謝
這裏有一個.htaccess
文件從CodeIgniter PHP框架複製:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
這會將所有不是index.php
,robots.txt
或images
文件夾中的任何內容重定向到index.php/$1
,其中$1
是用戶輸入的URL。
您需要這些規則爲:
index.php
會導致infinte環 - http://localhost/index.php/index.php/index.php/...
robots.txt
的是,搜索引擎使用的一個重要文件。它只是純文本;你不希望它被你的代碼處理。試試這個規則:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^index\.php/ index.php%{REQUEST_URI} [L]
條件是排除被改寫現有文件的請求。
感謝噸秋葵 – webkul 2009-09-17 20:30:41
你的規則會阻止任何只有*開頭的URL路徑被'index.php','images'或'robots.txt'重寫。 – Gumbo 2009-09-17 20:34:09