如何在lighttpd中启用mod重写

发布于 2024-08-31 14:56:05 字数 54 浏览 1 评论 0原文

我需要在 lighttpd 中启用模式重写 它不应该显示index.php扩展名......

i need to enable mode rewrite in lighttpd
it should no display the index.php extension ....

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

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

发布评论

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

评论(2

不知所踪 2024-09-07 14:56:05

如果我理解你的问题,你需要将 /index 重写为 /index.php。这应该可以解决问题。

server.modules += ("mod_rewrite")
url.rewrite-once = ( 
    "^(.*)$" => "$1.php"
);

注意,这也会转发 url,例如 /image.jpg -> /image.jpg.php。如果您需要更复杂的解决方案,请调整您的问题。

If I'm understanding your question, you need to rewrite /index to /index.php. This should do the trick.

server.modules += ("mod_rewrite")
url.rewrite-once = ( 
    "^(.*)$" => "$1.php"
);

Note, this will also forward url's such as /image.jpg -> /image.jpg.php. If you need a more complex solution please adjust your question.

凉月流沐 2024-09-07 14:56:05

我相信他们可能一直在寻找如何重写例如: /index.php/class/function 到 /class/function ,例如在 WordPress 和 PHP MVC 框架中使用的。

这很容易做到。使用文本编辑器打开 /etc/lighttpd/lighttpd.conf 并通过取消注释(删除 #)来启用重写模块。然后它看起来像这样

server.modules = (
    "mod_access",
    "mod_alias",
    "mod_compress",
    "mod_redirect",
    "mod_rewrite",

:)

然后您只需将重写正则表达式添加到同一个文件中即可。在删除index.php的情况下,我使用的是:

url.rewrite-if-not-file = ("^/[^?]*(\?.*)?$" => "/index.php$1")

保存并退出,然后重新启动lighttpd。在 Debian 中,您可以执行以下操作: sudo service lighttpd restart && sudo service lighttpd status

我总是运行第二个命令(&&之后)来检查服务状态并确保没有启动错误。之后,您就可以出发了!

I believe they may have been looking for how to rewrite for example: /index.php/class/function to /class/function, such as is used in Wordpress and PHP MVC Frameworks.

This is very easy to do. Open /etc/lighttpd/lighttpd.conf with a text editor and enable the rewrite module by uncommenting it (remove the #). It will then look something like this:

server.modules = (
    "mod_access",
    "mod_alias",
    "mod_compress",
    "mod_redirect",
    "mod_rewrite",

)

Then you simply add your rewrite regular expression to the same file. In the case of removing index.php, this is what I use:

url.rewrite-if-not-file = ("^/[^?]*(\?.*)?$" => "/index.php$1")

Save it and exit, then restart lighttpd. In Debian you would do: sudo service lighttpd restart && sudo service lighttpd status

I always run the second command (after &&) to check the service status and ensure there were no startup errors. After that, you should be good to go!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文