5

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

Ramesh
  • 51
  • 1
  • 1
  • 2

2 Answers2

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.

Kendall Hopkins
  • 43,213
  • 17
  • 66
  • 89
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!

Gregory Wolf
  • 121
  • 3