17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 12910 Views |
-
Rewrite rules for lighttpd

30 July 2007 at 12:15am Last edited: 2 August 2007 9:25am
So I downloaded Silverstripe v2.0.2b, installed it under lighttpd on Ubuntu and apart from the mod_rewrite warnings it went well. The issue is that on www.kissick.net.nz it will come up with the welcome default site ok and contact us, about us, etc. but as soon as I go to a URL that has a '?' in it, it breaks and simply returns an empty page. An example of this is http://www.kissick.net.nz/Security/login - upon submitting it attempts to go to http://www.kissick.net.nz/Security/?executeForm=LoginForm
My regex, mod_rewrite and url.rewrite skills leaves something to be desired.so maybe someone can help me out as I've only guessed based on rules I found in the Windows installer. I currently have the url.rewrite:
url.rewrite-once = (
"(?i)(/.*\.(jpe?g|png|css|js|gif|php))$" => "$0",
"^/(.*)(\?|$)(.*)" => "/sapphire/main.php?url=$1&$3"
)Any suggestions as to where I'm failing? Cheers, - Damian
-
Re: Rewrite rules for lighttpd

30 July 2007 at 2:49pm Last edited: 30 July 2007 2:50pm
I don't know lighttpd nor much regex, but I found this in C:\lighttpd\etc\lighttpd.conf my Windows SilverStripe install:
#### url handling modules (rewrite, redirect, access)
$HTTP["url"] !~ "\.pdf$" {
url.rewrite-once = (
"^/(.*)(\?|$)(.*)" => "/sapphire/main.php?url=$1&$3"
)
}Attached is the entire lighttpd.conf file in case you find it useful.
Hope this helps,
Elijah
Edit: Sorry, I didn't read your post closely enough, it seems you already found lighttpd.conf
-
Re: Rewrite rules for lighttpd

2 August 2007 at 2:46am
You should remove the \ before the "
I have the next line in lighttpd.conf:"^/silverstripe/(.*)(\?|$)(.*)" => "silverstripe/sapphire/main.php?url=$1&$3"
-
Re: Rewrite rules for lighttpd

2 August 2007 at 9:29am
Hans:
Oddly enough, when I encased the code init escaped the double-quotes. Have removed the tag pair now and you'll find that it pretty much matches what you have.I avoided $HTTP['url'] because I was told that a url.rewrite-once doesn't work inside that conditional. Of course, this seems to be incorrect since the windows installer runs with it fine. I also put the ' => $0' rule because without it, the css styling and images, etc. wouldn't show up. I secretly suspect something odd in my lighttpd setup so I might flatten it and/or just switch to Apache. If I get a chance I will triple-check the error and access logs but last time I checked they didn't help me much.
Cheers for your guys help so far.
-
Re: Rewrite rules for lighttpd

3 August 2007 at 7:43pm
Sorry, I didn't look at the first post where the \ are not there. Do you use symbolic links ? I noticed some problems when i linked silverstripe-2.0.2b to silverstripe and used the latter name in the rewrite rules. Otherwise I can send you my lighttpd.conf file if you are interested.
-
Re: Rewrite rules for lighttpd

3 August 2007 at 9:28pm
Hehe, I editing my first post to remove the code tag. No symlinks either.
I grow more confident it is something odd about my particular setup. I will look into it again at some stage. Cheers for the help. -
Re: Rewrite rules for lighttpd

6 February 2008 at 9:44pm
I had exactly the same problem and found a solution
First of all, I just like to say that there is currently no information in the Silverstripe help, or on the site from what I can see, on how to get Silverstripe rewrite rules going with lighttpd. So the only way of figuring the rewrite rules out, is by trying the Windows all-in-one installer, and copying the lighttpd configuration file from there, it looks like others are doing exactly what I had done here.
The problem is the Windows all-in-one installer seems to be bundled with an old version of lighttpd 1.4.10. The Windows all-in-one installer uses an $HTTP['url'] rule, which no longer seems to work in Lighttpd 1.4.18, either that, or it could be because I am wrapping it in an $HTTP['host'] block.
I had the same problem with Damo's rule, it worked for any pages without a ? in it, but as soon as you try to log in, things break. I had a really good look at it, and the problem is because of a greedy regex rule.
Damo's rule was:
"^/(.*)(\?|$)(.*)" => "/sapphire/main.php?url=$1&$3"
The problem is the first (.*) is greedy, which means it never gets to the (\?|$) part.
To fix it, simply change to:
"^/(.*?)(\?|$)(.*)" => "/sapphire/main.php?url=$1&$3"
*? is non-greedy, it repeats the previous item zero or more times. Lazy, so the engine first attempts to skip the previous item, before trying permutations with ever increasing matches of the preceding item.
Source:
-
Re: Rewrite rules for lighttpd

31 May 2008 at 5:54pm Last edited: 4 June 2008 7:11pm
Update 2: This code is obsolete, please check:
http://doc.silverstripe.com/doku.php?id=installation-on-lighttpd
Update: Since I last posted this, I have found two issues with my lighttpd config code I had posted:
1. If you have an image in your assets folder ending on .JPG in capitals instead of .jpg it doesn't work in admin.
2. Image previews do not show in admin, because they have text after the .jpg part for example: http://yoursite.com/assets/_resampled/AssetLibraryPreview-image.jpg?r=60205
The solution for #2 is before the $ on the first regex line, insert (.*?)
The solution for #1 can be done in different ways, if you only want to support .jpeg .jpg .JPEG and .JPG but not less obscure extensions like .JpEg then the following will do (and it will also be faster):
$HTTP["host"] == "yoursite.com" {
server.document-root = "/home/yoursite/public_html/"
url.rewrite-once = (
"(?i)(/.*\.(jpe?g|JPE?G|png|PNG|css|CSS|js|JS|gif|GIF|php|PHP|x?html?|X?HTML?))(.*?)$" => "$0",
"^/(.*?)(\?|$)(.*)" => "/sapphire/main.php?url=$1&$3"
)
server.error-handler-404 = "/sapphire/main.php"
}If you do want to support more obscure extensions such as .JpEg you will need a much more complex regex, something like this:
((j|J)(p|P)(e|E)?(g|G)|(p|P)(n|N)(g|G) ... etc
But in reality, I don't think anyone is going to use mixed case file extensions, so my first example would probably be much better, and faster too.
| 12910 Views | ||
| Go to Top | Next > |



