我需要为我的.htaccess文件去掉.php文件扩展名,并用一个尾部的斜杠替换它。如何使用.htaccess规则删除.php扩展名?
此外,我有一个profile.php页面,通常会使用数字查询字符串参数访问,如“profile.php?id=3
”。
因此,除了用斜线替换扩展名之外,如何使“profile.php?id=3
”看起来像“profile/3/
”?
到目前为止我只有第一行:
RewriteEngine on
我在哪里何去何从?
我需要为我的.htaccess文件去掉.php文件扩展名,并用一个尾部的斜杠替换它。如何使用.htaccess规则删除.php扩展名?
此外,我有一个profile.php页面,通常会使用数字查询字符串参数访问,如“profile.php?id=3
”。
因此,除了用斜线替换扩展名之外,如何使“profile.php?id=3
”看起来像“profile/3/
”?
到目前为止我只有第一行:
RewriteEngine on
我在哪里何去何从?
如果你是如此的新鲜......你真的应该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]
但这会做你想做的。现在不要懒惰。阅读手册!
这应该这样做
RewriteRule ^profile/(.*)$ profile.php?id=$1 [NC,L]
的[URL重写PHP中]
可能重复(http://stackoverflow.com/questions/2896015/url-rewriting-in-php) – Artefacto 2010-06-20 21:19:33