[英]How can I remove the .php extension using .htaccess rules?
I need for my .htaccess file to take away the .php file extension and replace it with just a trailing slash. 我需要我的.htaccess文件删除.php文件扩展名并将其替换为尾随的斜杠。
Also, I have a profile.php page which will normally be visited with a numeric querystring parameter, like " profile.php?id=3
". 另外,我还有一个profile.php页面,通常将使用数字查询字符串参数来访问该页面,例如“
profile.php?id=3
”。
So on top of replacing extensions with slashes, how do I make " profile.php?id=3
" look like " profile/3/
"? 因此,除了用斜杠替换扩展名外,如何使“
profile.php?id=3
”看起来像“ profile/3/
”?
So far all I have is the first line: 到目前为止,我所拥有的只是第一行:
RewriteEngine on
Where do I go from here? 我从这里去哪里?
If you're so new... you really should 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]
But this will do what you want. 但这会做您想要的。 Now don't be lazy.
现在不要偷懒。 Read the manual!
阅读手册!
这应该做
RewriteRule ^profile/(.*)$ profile.php?id=$1 [NC,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.