SE 友好 URL apache 代码片段

发布于 2024-09-04 16:34:44 字数 176 浏览 2 评论 0原文

我希望将 example.com/23-45 转换为 example.com?id=23-45

您能否发布我应该添加到 .htaccess 文件中的代码以使这项工作 (这是我应该做的一切来完成这项工作 - 将一段代码添加到 .htaccess 文件吗?)

I want example.com/23-45 be transformed to example.com?id=23-45

Could you please post the code I should add to .htaccess file to make this work
(Is this everything I should do to make this work - add a piece of code to .htaccess file?)

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

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

发布评论

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

评论(2

扶醉桌前 2024-09-11 16:34:44

您必须在 Apache 的 httpd.conf 中启用 mod_rewrite。要使用 .htaccess,您还必须在主配置中为 .htaccess 目录提供 AllowOverride FileInfoOptions FollowSymLinks。请参阅文档

之后,根文档目录中的 .htaccess 应该具有:

RewriteEngine on
RewriteRule ^\d+-\d+$ ?id=$0 [B]

You have to have mod_rewrite enabled in Apache's httpd.conf. To use a .htaccess, you also have to have AllowOverride FileInfo and Options FollowSymLinks for the .htaccess directory in the main configuration. See the docs.

After that, the .htaccess in the root docs directory should have:

RewriteEngine on
RewriteRule ^\d+-\d+$ ?id=$0 [B]
惯饮孤独 2024-09-11 16:34:44

这对我有用

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9\-]+) ?id=$0

That's what worked for me

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