2013-04-04 57 views
1

我想要兩個國防部重寫。讓我解釋。多ModRewrite - .htaccess


- 我需要一個重寫,如果沒有文件存在或目錄存在,重定向到一個用戶頁面。 | 我已經這樣做了。 - 接下來,我想從.php文件中刪除擴展名。

我已經完成了第一次,我只是無法弄清楚我將如何做第二次?


我已代碼:

RewriteEngine On 


RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 

RewriteRule ^(.*)$ users.php?name=$1 [QSA,L] 

所以我需要什麼,我只需要刪除PHP擴展,並保持當前重寫工作。

+0

我認爲你必須沒做什麼。只是不要在請求中包含php擴展,你的規則已經將不存在的所有內容重定向到'users.php'。如果您需要根據請求中的參數映射資源,請舉例說明。 – 2013-04-04 13:55:45

回答

1

這應該是你的完整的.htaccess:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

## To internally forward /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.*?)/?$ $1.php [L] 

## redirect to a userpage 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-l 
RewriteRule ^(.*)$ users.php?name=$1 [QSA,L] 
+0

非常感謝工作! :D – 2013-04-04 15:26:42

+0

不客氣,很高興知道它解決了。 – anubhava 2013-04-04 15:34:27

0

刪除.php擴展名:

RewriteEngine On 
# turn on the mod_rewrite engine 

RewriteCond %{REQUEST_FILENAME}.php -f 
# IF the request filename with .php extension is a file which exists 
RewriteCond %{REQUEST_URI} !/$ 
# AND the request is not for a directory 
RewriteRule (.*) $1\.php [L] 
# redirect to the php script with the requested filename 

只是點:

http://www.mysite.com/index

+0

對不起,我以爲我更清楚。我需要兩個,不只是刪除.php擴展名。 – 2013-04-04 01:43:34

+0

如果您願意在上市前試用.htaccess文件。我發現一個有用的文檔是:http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html這應該清除任何其他問題 – 2013-04-04 01:47:25

+0

好吧,看起來不錯。謝謝。 – 2013-04-04 01:48:05