I’m trying to transfer a PHP project from apache to lighttpd. I have the following rewrite in the apache:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !.(js|ico|gif|jpg|jpeg|png|css|ttf)$ /index.php?_url=/$1 [QSA,L]
I can’t manage to translate it to lighttpd mod_rewrite.
Here are some of my attempts:
url.rewrite-if-not-file = (
# try with two separate matches - when the request ends with file.ext
".(?!(js|ico|gif|jpg|jpeg|png|css|ttf))[?]{0,1}(.*)$" => "/index.php?_url=/$1",
# if the request ends with /
"/[?]{0,1}$" => "/index.php?_url=/"
# ".+/(.*)?(.*)" => "/index.php?_url=/$1",
# "((?!.(js|ico|gif|jpg|jpeg|png|css|ttf)).*)" => "/index.php?_url=/$1"
# "^([^?(js|ico|gif|jpg|jpeg|png|css|ttf)]+)[?]{0,1}(.*)$" => "/index.php?_url=$1&$2"
)
With the last version the only difference I see the only difference in PHP’s $_SERVER[‘SCRIPT_NAME’]. It is:
[SCRIPT_NAME] => /v1/en/entity/method/ # with the apache
[SCRIPT_NAME] => /index.php # with the lighttpd
The request itself is:
https://api.local/v1/en/entity/method/
2
Answers
first of all you must place this code in
/etc/lighttpd/conf-enabled/10-rewrite.conf
afterserver.modules += ("mod_rewrite")
or in the
/etc/lighttpd/conf-enabled/90-vhosts.conf
at the corresponding vhost (respectively in the conf-available and point a symlink to conf-enabled)you cannot place it in .htaccess
BUT OK lets admit this is the domain http://www.example.com
this should work the same way as in Apache.
(I haven’t tested it)
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModRewrite