Lighttpd to nginx vhost rewirte rule conversion - mod-rewrite

I have following lighttpd redirect rules and would need to convert them to nginx:
url.rewrite-once = (
"^/misc(.*)" => "/misc$1",
"^/show_fileupload.php(.*)" => "/show_fileupload.php$1",
"^/flash(.*)" => "/flash$1",
"^/images(.*)" => "/images$1",
"^/css(.*)" => "/css$1",
"^/js(.*)" => "/js$1",
"^/filestore(.*)" => "/filestore$1",
"/(([a-f0-9]{32})/)?(app/(.+?)/)(lang/(\w{2}-\w{2}|\w{2}|)/)?/*([^\?]*)(?:\?(.*))?" => "/$4.php?rs_module_uri=$7&rs_session=$2&rs_app=$4&rs_lang=$6&$8",
"/(([a-f0-9]{32})/)?(app//)?(lang/(\w{2}-\w{2}|\w{2}|)/)?/*([^\?]*)(?:\?(.*))?" => "/main.php?rs_module_uri=$6&rs_session=$2&&rs_lang=$5&$7",
)
How to convert especially the last two lines?

I finally got it to work, it's even not that different:
rewrite "/(([a-f0-9]{32})/)?(app/(.+?)/)(lang/(\w{2}-\w{2}|\w{2}|)/)?/*([^\?]*)(?:\?(.*))?" /$4.php?rs_module_uri=$7&rs_session=$2&rs_app=$4&rs_lang=$6&$8 last;
rewrite "/(([a-f0-9]{32})/)?(app//)?(lang/(\w{2}-\w{2}|\w{2}|)/)?/*([^\?]*)(?:\?(.*))?" /main.php?rs_module_uri=$6&rs_session=$2&&rs_lang=$5&$7 last;

Related

lighttpd redirect and rewrite to internal server

I am attempting to set up a proxy + rewrite with lighttpd.
I am trying to reverse proxy to two separate servers. The first is meant to be at root (192.168.1.198:7000) and the second is meant to be accessed through the /ram/ directory (192.168.1.197:8000). I am using version 1.4.38-1 of lighttpd and do not have the option of upgrading.
The below is the relevant portion of my lighttpd.config, I am hoping someone can point me to my error!
$SERVER["socket"] == ":82" {
url.rewrite-once = ( "^/ram/(.*)$" => "/$1" )
proxy.server = ( "" => (
"" =>
( "host" => "192.168.1.197",
"port" => 8000
)
)
)
}
else $HTTP["host"] == "subdomain.example.com" {
proxy.balance = "hash"
proxy.server = ( "" => ( ( "host" => "192.168.1.198", "port" => 7000 ) ) )
$HTTP["url"] =~ "(^/ram/)" {
proxy.server = ( "" => (
"" =>
( "host" => "127.0.0.1",
"port" => 81
)
)
)
}
}
FYI, I see three backend proxy servers configured, not two.
Also, all requests from a client to port :82 on your server will be handled by the first conditional block. The 'else $HTTP["host"] == "subdomain.example.com"' will never be seen by clients connecting to port :82 on your lighttpd server.
If you want all requests with Host: subdomain.example.com to follow the instructions in that conditional block, then make that section a standalone 'if' rather than an 'else' tacked on to the first condition ($SERVER["socket"] == ":82")

A PHP Error was encountered Severity: Notice Message: Array to string conversion Filename: mysql/mysql_driver.php Line Number: 552

Model :
function trans_gdc_add()
{
$trans_gdc_gc_package[0] = $this->input->post('trans_gdc_gc_package');
$trans_gdc_gc_package1 = implode(",", $trans_gdc_gc_package[0]);
$add=array(
'trans_gdc_no' => $this->input->post('trans_gdc_no'),
'trans_gdc_to' => $this->input->post('trans_gdc_to'),
'trans_gdc_vehicle_no' => $this->input->post('trans_gdc_vehicle_no'),
'trans_gdc_vehicle_type' => $this->input->post('trans_gdc_vehicle_type'),
'trans_gdc_vehicle_chas' => $this->input->post('trans_gdc_vehicle_chas'),
'trans_gdc_vehicle_make' => $this->input->post('trans_gdc_vehicle_make'),
'trans_gdc_vehicle_eng' => $this->input->post('trans_gdc_vehicle_eng'),
'trans_gdc_vehicle_permit' => $this->input->post('trans_gdc_vehicle_permit'),
'trans_gdc_vehicle_pol' => $this->input->post('trans_gdc_vehicle_pol'),
'trans_gdc_vehicle_isby' => $this->input->post('trans_gdc_vehicle_isby'),
' trans_gdc_date' => $this->input->post(' trans_gdc_date'),
'trans_gdc_from' => $this->input->post('trans_gdc_from'),
'trans_gdc_driver_add' => $this->input->post('trans_gdc_driver_add'),
'trans_gdc_lic_no' => $this->input->post('trans_gdc_lic_no'),
'trans_gdc_vehilce_owner_name' => $this->input->post('trans_gdc_vehilce_owner_name'),
'trans_gdc_vehicle_owner_add' => $this->input->post('trans_gdc_vehicle_owner_add'),
'trans_gdc_vehicle_owner_mob' => $this->input->post('trans_gdc_vehicle_owner_mob'),
'trans_gdc_broker_name' => $this->input->post('trans_gdc_broker_name'),
'trans_gdc_broker_mob' => $this->input->post('trans_gdc_broker_mob'),
'trans_gdc_gc_no' => $this->input->post('trans_gdc_gc_no'),
'trans_gdc_gc_package' => $trans_gdc_gc_package1,
'trans_gdc_gc_cont' => $this->input->post('trans_gdc_gc_cont'),
'trans_gdc_gc_weight' => $this->input->post('trans_gdc_gc_weight'),
'trans_gdc_gc_freight' => $this->input->post('trans_gdc_gc_freight'),
'trans_gdc_gc_consignor' => $this->input->post('trans_gdc_gc_consignor'),
'trans_gdc_gc_consignee' => $this->input->post('trans_gdc_gc_consignee'),
'status' => '1'
);
return $this->db->insert('trans_gc_add',$add);
}
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: mysql/mysql_driver.php
Line Number: 552
Please help me to resolve this issue .
check this
' trans_gdc_date' => $this->input->post(' trans_gdc_date'),
space might be giving the problem, repla
'trans_gdc_date' => $this->input->post(' trans_gdc_date'),
You can't directly merge strings in arrays!
your trying to merge concatinate strings with arrays or lets say arrays with string thats not possible
General Example
<?php
$stack = array("Orange", "Banane");
array_push($stack, "Apfel", "Himbeere");
print_r($stack);
?>
for your code Example
// array push tiggers a php array as stack!
$add=array()
array_push($add, 'trans_gdc_no', $this->input->post('trans_gdc_no'));
array_push($add, 'trans_gdc_to', $this->input->post('trans_gdc_to'));
print_r($add);

Cannot get url.rewrite and alias.url to play nice together

Current relavent config from lighttpd.conf:
url.rewrite = (
"^/(.*)\.(.+)$" => "$0",
"^/(.+)/?$" => "/index.php/$1",
)
and
alias.url += (
"/xcache/" => "/usr/share/xcache/"
)
I cant get them to work together. From what I understand, the rewrite hijacks the "/xcache/" url thus not triggering the alias.url.
They both work perfectly fine on their own, but cannot get them to work together. Is there a way to exclude certain strings from the url.rewrite expression?
Solved it:
url.rewrite = (
"^/(xcache)/(.*)" => "$0",
"^/(.*)\.(.+)$" => "$0",
"^/(.+)/?$" => "/index.php/$1",
)
alias.url += (
"/xcache/" => "/usr/share/xcache/"
)

how to setup lighttpd for subdirectory mappings?

For the same host name, I want to do mapping like the following
/subdirectory/_different_end_points_.json map to 127.0.0.1:9001
/_different_end_points_.json map to 127.0.0.1:9002
How to do that? per documentation, it's required that the else clause has to match on a condition as well, which drives me nuts (as a beginner on regular expression)
Have you tried something like that:
$HTTP["url"] =~ "^/subdirectory/_different_end_points_.json" {
proxy.server = (
"/" => (("host" => "127.0.0.1", "port" => 9001))
)
}
else $HTTP["url"] =~ "^/_different_end_points_.json" {
proxy.server = (
"/" => (("host" => "127.0.0.1", "port" => 9002))
)
}
That way, you match each url that starts with /subdirectory/_different_end_points_.jso or (in the else) /_different_end_points_.json.
But be sure that your url realy start with the regex! I mean: h*tp://sample.com/subdirectory/_different_end_points_.json and h*tp://sample.com/_different_end_points_.json

lighttpd rewrite-once rule isn't working

I just got some problems serving static files via Lighttpd.
Here's what I would want to do:
www.example.ch is my domain.
If a call comes to www.example.ch/static/.....css
then I want to reroute it and actually serve the file from static.example.ch/files/....css (see my url.rewrite-once rule).
Somehow this just doesn't work. Am I missing something completely?
$HTTP["host"] =~ "(^|\.)example\.ch$" {
fastcgi.server = (
"/django.fcgi" => (
"main" => (
"socket" => env.HOME + "/webqs/webqs.sock",
"check-local" => "disable",
)
),
)
alias.url = (
"/media" => env.HOME + "/webqs/media",
)
url.rewrite-once = (
"^(/media.*)$" => "$1",
"^/favicon\.ico$" => "/media/favicon.ico",
"^(/static.*)$" => "http://static.example.ch/files/$1",
"^(/.*)$" => "/django.fcgi$1",
)
}
Given the regular expression "^(/static.*)$" it looks like $1 is going to contain /static/...css. Is there a static/ directory under your files/ directory? If not, try changing the regular expression to something like:
"^/static/(.*)$"
This should match everything after /static/ but won't also include the string /static/.

Resources