Mod rewrite for opencart in lighttpd - mod-rewrite

These are the rules in lighttpd.conf
$HTTP["host"] =~ "^(www\.)?mysite.com" {
url.rewrite-once = ( "^/$" => "/index.php?route=common/home" )
url.rewrite-if-not-file = ( "^/(.*)" => "/index.php?_route_=$1" )
url.access-deny = ( ".tpl", ".ini", ".log" )
server.error-handler-404 = "/index.php?route=error/not_found"
index-file.names = ( "index.php" )
}
Everything works fine. When i open www.mysite.com/adidas it works, but when i try to open www.mysite.com/adidas?page=2 it gives me error404.
And when i try to open www.mysite.com/admin it gives me again error404, but when i open www.mysite.com/admin/index.php it works...
How can i fix it..

Found this article which seems to answer your first issue. For the admin issue, I'm assuming you need to at least use /admin/ including the second forward slash

Related

Having issues running a script via cgi in lighttpd

I have the following piece in my config file:
cgi.assign = ( ".sh" => "" )
$HTTP["url"] =~ "^/urlpath/" {
$HTTP["querystring"] =~ "cams=on" {
cgi.assign = ( "" => "/scriptpath/CamsOn" )
}
$HTTP["querystring"] =~ "cams=off" {
cgi.assign = ( "" => "/scriptpath/CamsOff" )
}
url.redirect = ( "^/urlpath/" => "http://somewebsite" )
}
I have the cgi module loaded:
server.modules = (
"mod_redirect",
"mod_access",
"mod_cgi",
"mod_accesslog" )
Now "CamsOn" and "CamsOff" are shebanged shell scripts. To be honest I had done this before and had it working but my server crashed and I lost my configs. For some reason I can't figure for the life of me how to get it working. I do the redirect so I don't have to actually create the "urlpath" page. The redirect works fine inside the $HTTP["url"] piece, and I've even tested the querystring portion by nesting a redirect inside that just takes it to google.com; urlpath/?cams=on sent me to google accordingly.
What am I doing wrong?
Update:
I was to get it to work using
$HTTP["url"] =~ "^/urlpath/" {
$HTTP["querystring"] =~ "cams=on" {
cgi.assign = ( "" => "/scriptpath/CamsOn" )
}
$HTTP["querystring"] =~ "cams=off" {
cgi.assign = ( "" => "/scriptpath/CamsOff" )
}
}
I'm thinking that the redirect was getting parsed first, so when the address changed, it no longer fit the URL and querystring comparisons. Can I change this? The idea is to make the urlpath dynamic and updated in the conf file dynamically. This is why I have the redirect send you to another address. This way I also don't need to do html editing or create additional folders.
What am I doing wrong?
a) did not make backups
b) did not make backups
c) did not make backups
d) did not look in your own stackoverflow post history
See Can't figure out how to receive http requests using lighttpd
If you want to reduce the number of places you edit in your config file, you can assign a value to a variable in lighttpd.conf and use the variable in lighttpd.conf. See var.* in
https://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_Configuration
var.camsurlpath = "/urlpath/"
$HTTP["url"] =~ "^" + var.camsurlpath {
...
}

lighttpd configuration to proxy/rewrite from one domain to another

i need to setup proxy/rewrite on lighttpd!
i have server1, which serves via http 2 different web app paths:
* http://server1/path1
* http://server1/path2
also, i have lighttpd server in front of server1
i want to setup rewriting and/or proxing on lighttpd, so that each of the 2 paths would be served as root path on different domains:
* requests to http://server2.com/* are proxied/rewrited to http://server1/path1/*
* requests to http://server3.com/* are proxied/rewrited to http://server1/path2/*
important:
server2.com and server3.com can access server1 only via http
redirects are not the option, users of server2.com & server3.com shouldn't not know that the actual web apps are served from different paths of server1.
Is it possible?
Your need is known by lighttpd developers from several years.
It is answered by a workaround or new feature depending on the version.
Lighttpd 1.4
A workaround is explained in the bugtracker : bug #164
$HTTP["url"] =~ "(^/path1/)" {
proxy.server = ( "" => ("" => ( "host" => "127.0.0.1", "port" => 81 )))
}
$SERVER["socket"] == ":81" {
url.rewrite-once = ( "^/path1/(.*)$" => "/$1" )
proxy.server = ( "" => ( "" => ( "host" => "server2.com", "port" => 80 )))
}
Lighttpd 1.5
They added this feature with this command (official documentation) :
proxy-core.rewrite-request : rewrite request headers or request uri.
$HTTP["url"] =~ "^/path1" {
proxy-co...
proxy-core.rewrite-request = (
"_uri" => ( "^/path1/?(.*)" => "/$1" ),
"Host" => ( ".*" => "server2.com" ),
)
}
Update: lighttpd 1.4.46 (released in 2017) introduced proxy.header which can perform limited URL-prefix rewriting. More info at lighttpd mod_proxy

Batch File Protocol Parser

My custom defined protocol (phpfile) lets me open php-files in an editor through the browser. The only problem is, it gives the full url, that is different in each browser, i've seen:
phpfile:/[file]
phpfile:/[file]/
phpfile://[file]/
phpfile://[file]
All these need to be converted to just [file]. The problem is that I get a syntax error. What is the correct syntax?
set var=%1
if("%var:~0,9%"=="phpfile:/")
{
set url = %var:~9%
}
else
{
set url = %var:~10%
}
if(%var:-1,1% == "/")
{
url = %url:~0,-1%
}
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" url
=== Edit ===
I now have the following, but it is adding "" at the end of the url
SETLOCAL enabledelayedexpansion
set var=%1
if %var:~0,9%=="phpfile:/" (
set url = %var:~9%
) else (
set url = %var:~10%
)
if "%var:~-1%"=="\" (
set url = %url:~0,-1%"
)
if "%var:~-1%"=="/" (
set url = %url:~0,-1%"
)
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" %url:"=%
That's because you wrote some horrible bastard between batch files and C but certainly no language that is in use anywhere.
Try the following:
setlocal enabledelayedexpansion
set "var=%~1"
if "!var:~0,9!=="phpfile:/" (
set "url=!var:~9!"
) else (
set "url=!var:~10!"
)
if "!var:-1,1!"=="/" (
set "url=!url:~0,-1!"
)
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" "!url!"
Delayed expansion was used primarily to deal better with some characters that cause trouble in batch files. Generally though, I wonder how you would ever have expected your code to work.
There were quite a few problems in your code, this should fix things:
set var="%1"
if %var:~0,9%=="phpfile:/" (
set url="%var:~9%"
) else (
set url="%var:~10%"
)
if "%var:-1,1%"=="/" (
set url="%url:~0,-1%"
)
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" url
You can check the syntax of batch file commands using help <command>. IF statements don't use curly braces, or require round brackets around the conditional statement.

Simple MediaWiki extension debugging

I am trying to write my very first MediaWiki extension and need some way to debug it. What is the simplest way to do it? Showing a message, logging into a file etc. would be fine. I just want to slowly progress over the code and see where it breaks and what the content of a variable is.
I've tried (from http://www.mediawiki.org/wiki/Manual:How_to_debug#Useful_debugging_functions)
// ...somewhere in your code
if ( true ) {
wfDebugLog( 'myext', 'Something is not right: ' . print_r( 'asdf', true ) );
}
in extensions/myext/myext.php and added to LocalSettings.php
require_once( 'extensions/myext/myext.php' );
# debugging on
$wgDebugLogGroups = array(
'myext' => 'extensions/myext/myextension.log'
);
but then my Wiki doesn't work at all (error 500). With the above code removed from myext.php everything's fine (with $wgExtensionCredits in myext.php, I can see myext in the Special:Version).
Is it the right thing to do (then what is the mistake) or is there a better/simpler way to start with?
500 means you have a syntax error or wrong configuration somewhere. Have you followed the instructions at Manual:How to debug and turned on PHP logging, so you can at least see what is causing the error? Alternatively, take a look at your Apache server log.
Also, you'll want to turn on debugging before you load your own extension!
Add these to LocalSettings.php for debugging:
error_reporting( -1 );
ini_set( 'display_startup_errors', 1 );
ini_set( 'display_errors', 1 );
$wgShowExceptionDetails=true;
$wgDebugToolbar=true;
$wgShowDebug=true;
$wgDevelopmentWarnings=true;
$wgDebugDumpSql = true;
$wgDebugLogFile = '/tmp/debug.log';
$wgDebugComments = true;
$wgEnableParserCache = false;
$wgCachePages = false;
You can log debug messages with wfDebug();
Learn more at https://www.mediawiki.org/wiki/Manual:Structured_logging/en

How to create a link in Sinatra that points to a directory of files?

I have an application that calls an other application that populates a directory. Once it is finished I want to provide a link to the directory that contains the created files and people can examine or download them via the browser:
For example this works to provide a link to a single file: (Note this uses HAML) but the idea is the same
%p
- output_href = File.join("..","..","test_runs",File.basename(#dealclick_test_run.result_filename) )
Result file =
%a{:id => "result-file", :href => "#{output_href}"}
= File.basename(#dealclick_test_run.result_filename)`
The corresponding code for the directory doesn't work:
%p
Results:
- output_href = File.join("..","..","test_runs",File.basename(#dp_test_run.result_filename) )
%a( id = "dealprocessor_results" href = "#{output_href}" )
= File.basename(#dp_test_run.result_filename)
What am I doing wrong?
%a( id = "dealprocessor_results" href = "#{output_href}" )
should be
%a(:id = "dealprocessor_results" :href = "#{output_href}" )

Resources