2010-06-20 145 views
0

我需要爲我的.htaccess文件去掉.php文件擴展名,並用一個尾部的斜槓替換它。如何使用.htaccess規則刪除.php擴展名?

此外,我有一個profile.php頁面,通常會使用數字查詢字符串參數訪問,如「profile.php?id=3」。

因此,除了用斜線替換擴展名之外,如何使「profile.php?id=3」看起來像「profile/3/」?

到目前爲止我只有第一行:

RewriteEngine on 

我在哪裏何去何從?

+1

可能重複(http://stackoverflow.com/questions/2896015/url-rewriting-in-php) – Artefacto 2010-06-20 21:19:33

回答

4

如果你是如此的新鮮......你真的應該read the manual

// if not a file 
RewriteCond %{SCRIPT_FILENAME} !-f 
// if not a directory 
RewriteCond %{SCRIPT_FILENAME} !-d 
// pass all params back to index.php 
// QSA stands for query string append 
// L stands for last rule 
RewriteRule (.*) index.php?$1 [QSA,L] 

但這會做你想做的。現在不要懶惰。閱讀手冊!

+0

不要偷懶, 谷歌! – sepehr 2010-06-20 21:24:09

+3

毫無意義地告訴他在你爲他完成工作之後不要懶惰:P – 2010-06-20 21:24:45

+1

@MrXexxed,你是對的......你是對的......不應該有! :) – Frankie 2010-06-20 21:39:57

0

這應該這樣做

RewriteRule ^profile/(.*)$ profile.php?id=$1 [NC,L] 
的[URL重寫PHP中]