简体   繁体   English

如何在lighttpd中启用mod重写

[英]how to enable mod rewrite in lighttpd

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

If I'm understanding your question, you need to rewrite /index to /index.php. 如果我理解你的问题,你需要重写/索引到/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. 注意,这也将转发url,例如/image.jpg - > /image.jpg.php。 If you need a more complex solution please adjust your question. 如果您需要更复杂的解决方案,请调整您的问题。

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. 我相信他们可能一直在寻找如何重写例如:/index.php/class/function to / class / function,例如在Wordpress和PHP MVC框架中使用。

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 #). 使用文本编辑器打开/etc/lighttpd/lighttpd.conf并通过取消注释来启用重写模块(删除#)。 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: 在删除index.php的情况下,这是我使用的:

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

Save it and exit, then restart lighttpd. 保存并退出,然后重新启动lighttpd。 In Debian you would do: sudo service lighttpd restart && sudo service lighttpd status 在Debian中你会做: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! 在那之后,你应该好好去!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM