how to enable mod rewrite in lighttpd
Asked Answered
G

2

5

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

Grapple answered 7/5, 2010 at 6:56 Comment(0)
B
7

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.

Blowsy answered 7/5, 2010 at 7:0 Comment(0)
H
1

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!

Hug answered 3/8, 2016 at 17:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.