Remove index.php from URL using mod_rewrite in Lighttpd - url-rewriting

I'm trying to remove the index.php from https://test.mysite.com.br/api/index.php/get/0/32342543 with no success.
I've tried:
url.rewrite-once = (
"^/(test)(.*)” => “/$1$2",
"^/(.*)$” => “/index.php/$1"
)
and also:
url.rewrite = (
"^/(.*)\.(.+)$" => "$0",
"^/(.+)/?$" => "/api/index.php/$1"
)
But both didn't work. What is the correct syntax for url.rewrite?

enable lighttpd module "mod_rewrite" in /etc/lighttpd/lighttpd.conf

Related

lighttpd fastcgi: how to restore stripped URL path elements?

I'm implementing a (rather complex) RESTful API.
I use Lighttpd as web server with two FastCGI backends:
a generic PHP handler for the bulk of requests
a specialized C++ handler for several other requests
my current fastcgi.conf looks like (simplified):
server.modules += ( "mod_fastcgi" )
fastcgi.server = ( ".php" => ( "PHP" => (
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php.socket",
"check-local" => "disable",
"bin-environment" => ( "PHP_FCGI_CHILDREN" => "0", "PHP_FCGI_MAX_REQUESTS" => "500" ),
"bin-copy-environment" => ( "PATH", "SHELL", "USER" ),
"max-procs" => 1,
"broken-scriptfilename" => "enable"
)),
"/api/groupA" => ( "Server" => (
"socket" => "/tmp/fcgi-C.socket",
"check-local" => "disable",
)),
"/api/groupB" => ( "Server" => (
"socket" => "/tmp/fcgi-C.socket",
"check-local" => "disable",
)),
"/api/groupC" => ( "Server" => (
"socket" => "/tmp/fcgi-C.socket",
"check-local" => "disable",
)),
"/api/" => ( "PHP" => (
"bin-path" => "/usr/bin/php-cgi",
"socket" => "/tmp/php-P.socket",
"check-local" => "disable",
"bin-environment" => ( "PHP_FCGI_CHILDREN" => "0", "PHP_FCGI_MAX_REQUESTS" => "500" ),
"bin-copy-environment" => ( "PATH", "SHELL", "USER" ),
"max-procs" => 1,
"broken-scriptfilename" => "enable"
))
)
This means I filter prefixes intended for C++ handling and default the rest to PHP.
PHP part works as expected.
Problem here is C++ handler receives a truncated request path with "/group(A|B|C)" stripped away (everybody gets the path without the leading "/api", but that's OK).
How can I restore the full path?
Alternatively: Is there (or can I produce) some variable/header/whatever I can test in C++ to get the "missing part"?
I am fully prepared to cope with redundant information (e.g.: path restored to the full "/api/..."), but I need the information that has been dropped.
Only thing that comes to mind would be to differentiate the sockets and to have a filter restoring the information based on actual incoming socket but that seems overcomplex and very brittle; I'm hoping for a simpler solution, possibly involving URL-rewrite (I'm not familiar with Lighttpd configuration intricacies, I'm more of a C++/PHP/java coder, so I hope I overlooked something obvious ;) )
The original request from the client can be found in REQUEST_URI.
mod_fastcgi also has config options to allow a limited set of URL mangling for broken PHP.
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI

Lighttpd rewrite-if-not-file cannot process *php and *html in one rule

To enable a shorten-url service, I had to add a rewrite rule to my
lighttpd.conf. This seems to be important, otherwise shortlinks like
http://example.com/Xf6Y would return a 404 error. This is because Xf6Y
is not a file but a shortlink hash.
So I added these lines to my lighttpd.conf:
url.rewrite-if-not-file = (
"^/(.*)$" => "/index.php?fwd=$1"
)
This works excellently, except for websites that contain a index.html
instead of an index.php.
I tried to duplicate the rewrite rule, like url.rewrite-if-not-file = (
"^/(.)(\?.)?$" => "/index.php?fwd=$1",
"^/(.)(\?.)?$" => "/index.html?fwd=$1"
)
This resulted in a "duplicate rule" error, so lighttpd is
not able to restart.
Does anyone know how to write a rewrite rule that will redirect index.php and index.html?

CakePHP named paramaters in FireFox Causing issues

We have a cakephp app running on 2.0 and we seem to be having some encoding issues with Firefox.
The URL we are accessing is /newcms/core/users/index/conditions[User][group_id]:6 to apply a filter in out cms system.
In everything but FireFox we get the following on the request object
[params] => Array
(
[plugin] => core
[controller] => users
[action] => newcms_index
[named] => Array
(
[conditions] => Array
(
[User] => Array
(
[group_id] => 6
)
)
)
[pass] => Array
(
)
[prefix] => newcms
)
Which is correct and everything works fine, if we goto the same URL in FireFox we get
[params] => Array
(
[plugin] => core
[controller] => users
[action] => newcms_index
[named] => Array
(
[conditions%5BUser%5D%5Bgroup_id%5D] => 6
)
[pass] => Array
(
)
[prefix] => newcms
)
I have tried URL encoding the named condition value but with no luck..
Any suggestions?
It's probably not a great idea to be using brackets and an array structure in your URL.
Why not just use something like this?:
/newcms/core/users/index/user_group:6
Then process the data in the controller.
Well after a bit of digging and playing around the latest version of cake in GitHub has fixed this FF issue (https://github.com/cakephp/cakephp/commit/e6905b44c3d4512b6989c59a1489bc983d88bcdc).
There is nothing incorrect about passing square brackets in the URI it was just an issue with the way FF encoded them differently than the other browsers.

Lighttpd rewrite for Codeigniter breaking on certain URLs

I moved from apache to lighttpd, and since then certain URLs break the rewriting and give 404. No details in access.log, error.log regarding what actual URL was hit.
These kind work:
http://192.168.1.250/loop/rest/admin
But not these:
http://192.168.1.250/loop/rest/admin/logs/file::log-2012-02-14.php
If I skip rewriting and use
http://192.168.1.250/loop/rest/index.php?/admin/logs/file::log-2012-02-14.php
I get what I want,
Here is my rewrite rule:
url.rewrite-once = (
"/(.*)\.(.*)" => "$0",
"/(css|files|img|js|stats)/" => "$0",
"^/([^.]+)$" => "/loop/rest/index.php/$1"
)
Any help would be appreciated.
I was just having the same issues when testing my codeigniter app on lighttpd
This worked for me:
url.rewrite = (
".*\.(js|ico|gif|jpg|png|swf|css|html)$" => "$0",
"^/(.*)$" => "index.php/$1"
)
maybe you could try this for your setup:
url.rewrite = (
".*\.(js|ico|gif|jpg|png|swf|css|html)$" => "$0",
"^/(.*)$" => "/loop/rest/index.php/$1"
)
Make sure you have uncommented mod_rewrite at the top.. it comes default with a # in front of it.
I have found the correct rules:
First of all please make sure that your root directive points to the root of your CI setupd.
root /var/www/loop;
Then this location directive will work perfectly fine:
location /
{
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
}

Lighttpd url rewrite removes querystring variables

I am rewriting a URL in Lighttpd using
url.rewrite-once = (
"^/(.*)\.(.+)$" => "$0",
"^/(.+/?)\??$" => "/index.php?q=$1"
)
So that all urls are passed to index.php as variable q. However when I visit http://mydomain.com/account/edit?user=5 my script at index.php gets
q=account/edit?user=5
on apache I would get all variables i.e.
q=account/edit AND
user=5
How can I preserve the variables in Lighttpd?
(the first part of the url.rewrite rule is to ensure that files that exist are displayed properly)
Try something like this:
"^/something/(\d+)(?:\?(.*))?" => "/index.php?bla=$1&$2"
or this
"^/([^.?]*)\?(.*)$" => "/index.php?q=$1&$2",
"^/([^.?]*)$" => "/index.php?q=$1"

Resources