Removing .php from urls with lighttpd (clean urls)

2019-06-11 14:13发布

问题:

I am migrating an over loaded server from apache2 to lighttpd, currently I am proxying all the static resources from the lighttpd server but that still doesn't fix the load problems.

I want to migrate everything to lighttpd but I've run into a problem.

Apache2 has multiviews functionality to clean up URLs which lighttpd doesn't.

I found the following code to do it in lighttpd

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

It works but it has two problems

1: website.com/ returns 404, I guess its trying to find /.php

2: website.com/user/Username also returns 404 (Its supposed to find user.php, then the php script does the rest by looking at $_SERVER['REQUEST_URI'])

How do I rewrite the code to fix these problems?

回答1:

I'd prolly try to use/add something like:

url.rewrite-once = (
 "^/$" => "/",
 "^/users/(.*)" => "/users/user.php"
)

http://redmine.lighttpd.net/wiki/1/Docs:ModRewrite
About your load problems: You might want to read about squid which has caching besides simple proxy features.