0

Could you advise me how to remove file extensions properly in lighttpd?

So that:

  1. Root directory ("/") is not going to be rewritten to "/.php"
  2. Open directory if trailing slash is missing
  3. All files can be accessed without extension

Another StackOverflow thread here have answers that do not fix (1): Rewriting with lighttpd - how to remove file extensions

Community
  • 1
  • 1
Atm
  • 183
  • 1
  • 10

1 Answers1

0

2) and 3) are mutually exclusive - how do you expect the system to know if blahBlah is meant to be a directory blahBlah or a file blahBlah.php?
1) is probably handled by DirectoryIndex, not by your rewrite rules

Germann Arlington
  • 3,315
  • 2
  • 17
  • 19
  • url.rewrite-once = ( "^(.*)/$" => "$1/" ) url.rewrite-if-not-file = ( "^([^?]*)(\?.*)?$" => "$1.php$2" ). This fixes 2) and 3) but not 1) – Atm Aug 07 '12 at 09:16
  • url.rewrite-if-not-file gives priority to existing file. So, if you have directory blahBlah and later create file blahBlah.php it will shadow the directory and make it inaccessible. One again 1) is most likely handled by DirectoryIndex which comes BEFORE your rewrite rules are even checked. – Germann Arlington Aug 07 '12 at 09:27
  • Germann, that is fine. But re 1) there is no DirectoryIndex in the lighttpd. – Atm Aug 07 '12 at 09:29
  • There is "index-file.names". and it it is set to index.php. However, requests to core directory /?request=example do not go to index.php, instead they go to /.php?request=example, so it results in error 404. I'd appreciate if anyone could help me resolve that problem. – Atm Aug 07 '12 at 09:32
  • OK, now I understand (I think) what your problem is in 1). It is being handled by your url.rewrite-if-not-file You need to add special case rewrite before that to rewrite `/\?(.*) /index.php\?$1` – Germann Arlington Aug 07 '12 at 09:46
  • Yeah, you are correct. Thank you. I have edited the config and it now looks like this: url.rewrite-once = ( "^(.*)/(\?.*)?$" => "$1/$2" ) url.rewrite-if-not-file = ( "^([^?]*)(\?.*)?$" => "$1.php$2" ) However it doesn't really resolve problem (2) as you suggested. But it's fine as is. If anyone have an idea how to make this config better let me know. – Atm Aug 07 '12 at 09:54