[英]How can I remove the .php extension using .htaccess rules?
我需要我的.htaccess文件删除.php文件扩展名并将其替换为尾随的斜杠。
另外,我还有一个profile.php页面,通常将使用数字查询字符串参数来访问该页面,例如“ profile.php?id=3
”。
因此,除了用斜杠替换扩展名外,如何使“ profile.php?id=3
”看起来像“ profile/3/
”?
到目前为止,我所拥有的只是第一行:
RewriteEngine on
我从这里去哪里?
如果您是新手,那么您真的应该阅读该手册 。
// 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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.