Php 如何在lighttpd中启用mod rewrite

Php 如何在lighttpd中启用mod rewrite,php,mod-rewrite,lighttpd,Php,Mod Rewrite,Lighttpd,我需要在lighttpd中启用模式重写 它不应该显示index.php扩展名……如果我理解您的问题,您需要将/index重写为/index.php。这应该能奏效 server.modules += ("mod_rewrite") url.rewrite-once = ( "^(.*)$" => "$1.php" ); 注意,这还将转发url,例如/image.jpg->/image.jpg.php。如果您需要更复杂的解决方案,请调整您的问题。我相信他们可能一直在寻找如何将例如:

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

如果我理解您的问题,您需要将/index重写为/index.php。这应该能奏效

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

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

我相信他们可能一直在寻找如何将例如:/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

我总是运行第二个命令(在&&)来检查服务状态并确保没有启动错误。在那之后,你应该可以走了