2010-12-23 59 views
0

我希望能夠在使用QUERY_STRING時從我的URL中隱藏index.php和.php。使用QUERY_STRING時隱藏index.php和.php

現在,我成功地隱藏in​​dex.php文件(除訪問某些目錄時),在我的.htaccess中的以下內容:

RewriteEngine On 
RewriteCond $1 !^(codex|_core|admin|index\.php) [NC] 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

我這樣做是因爲我有一定​​的功能,如登錄/註銷/註冊,作爲頁面:example.com/login

但是,我也有一些靜態頁面,不會受益於一堆PHP函數中的一個文件......例如。 com/terms-and-conditions.php

在sp無法統一,如何將該網址轉換爲example.com/terms-and-conditions而不會破壞example.com/login?這甚至有可能嗎?我已經嘗試添加.php刪除重寫有關index.php刪除重寫(顯然刪除.php從index.php)無濟於事。

我曾嘗試使用位於here的解決方案,但它打破了example.com/login--我假設因爲我使用函數/查詢的方式。有沒有我需要改變的地方?

回答

0

想通了!只需要將兩者結合起來,這在回顧過程中顯得很明顯。 :)

RewriteEngine On 

# remove .php; use THE_REQUEST to prevent infinite loops 
RewriteCond %{HTTP_HOST} ^www\.domain\.com 
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP 
RewriteRule (.*)\.php$ $1 [R=301] 

RewriteCond $1 !^(codex|_core|admin|index\.php) [NC] 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

# remove slash if not directory 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} /$ 
RewriteRule (.*)/ $1 [R=301] 

# add .php to access file, but don't redirect 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteCond %{REQUEST_URI} !/$ 
RewriteRule (.*) $1\.php [L]