2010-06-20 144 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中]