如何使用 .htaccess 规则删除 .php 扩展名?

发布于 2024-09-06 01:18:58 字数 308 浏览 1 评论 0原文

我需要我的 .htaccess 文件去掉 .php 文件扩展名,并将其替换为尾随斜杠。

另外,我有一个 profile.php 页面,通常使用数字查询字符串参数访问该页面,例如“profile.php?id=3”。

那么,除了用斜杠替换扩展名之外,如何使“profile.php?id=3”看起来像“profile/3/”?

到目前为止,我所掌握的只是第一行:

RewriteEngine on

我该去哪里?

I need for my .htaccess file to take away the .php file extension and replace it with just a trailing slash.

Also, I have a profile.php page which will normally be visited with a numeric querystring parameter, like "profile.php?id=3".

So on top of replacing extensions with slashes, how do I make "profile.php?id=3" look like "profile/3/"?

So far all I have is the first line:

RewriteEngine on

Where do I go from here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

战皆罪 2024-09-13 01:18:58

如果您是新手...您确实应该阅读手册

// 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]

但这会做你想做的。现在别偷懒了。阅读手册!

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!

許願樹丅啲祈禱 2024-09-13 01:18:58

这应该可以做到

RewriteRule ^profile/(.*)$ profile.php?id=$1 [NC,L]

This should do it

RewriteRule ^profile/(.*)$ profile.php?id=$1 [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文