picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.83k stars 617 forks source link

lighttpd url rewrite #413

Closed tony5 closed 6 years ago

tony5 commented 6 years ago

does anyone have an idea how to convert the htaccess rules to lighttpd? I tried as mentioned here, https://github.com/picocms/Pico/issues/42#issuecomment-21218049 and I can't seem to make it work.

I have been trying for a long time and I am stuck. take care.

PhrozenByte commented 6 years ago

The rewrite rule in https://github.com/picocms/Pico/issues/42#issuecomment-21218049 was written for Pico 0.9 and isn't compatible with Pico 1.0. However, it should work again with Pico 2.0. Simply try the latest beta release of Pico 2.0 (see https://github.com/picocms/Pico/releases and #401) with the rewrite rule in https://github.com/picocms/Pico/issues/42#issuecomment-21218049. Don't worry about Pico 2.0 being in beta, it's actually ready-to-release, we just haven't finished the docs/website updates yet.

tony5 commented 6 years ago

@PhrozenByte thank you very much!! that did work!! I need to learn more about the subject. thanks for the fast reply and I will mark this closed. take care.

tony5 commented 6 years ago

opps, same issue it's not redirecting properly :(

tony5 commented 6 years ago

I think I have it? rewrite_url: true

PhrozenByte commented 6 years ago

Yes, you'll have to tell Pico that URL rewriting is available.

PhrozenByte commented 6 years ago

@tony5: You should furthermore make sure that access to Pico's internal files and dirs is denied (see https://github.com/picocms/pico-composer/blob/master/.htaccess). I guess (untested, just on the basis of https://github.com/picocms/Pico/issues/42#issuecomment-21218049 and lighttpd docs) that the rules should look like the following in the end:

$HTTP["host"] == "example.com" {
    url.rewrite-once = (
        "^/pico/(config|content|vendor|composer\.(json|lock|phar))(/|$)" => "/pico/index.php",
        "^/pico/(.+/)?\.(?!well-known(/|$))" => "/pico/index.php"
    )

    url.rewrite-if-not-file = (
        "^/pico(/|$)" => "/pico/index.php"
    )
}

If you've installed Pico to the document root rather than to the subdirectory pico/, the rules should look like the following:

$HTTP["host"] == "example.com" {
    url.rewrite-once = (
        "^/(config|content|vendor|composer\.(json|lock|phar))(/|$)" => "/index.php",
        "/\.(?!well-known(/|$))" => "/index.php"
    )

    url.rewrite-if-not-file = (
        "^" => "/index.php"
    )
}

Can you please test these rules? Please make sure that access to e.g. http://example.com/pico/config/config.yml is denied (Pico's 404 page should show up) and give me feedback about whether this works or not, I'll then add it to the Pico docs.

#edit: Fixing regex for dot-files.

tony5 commented 6 years ago

@PhrozenByte it does work! and Pico's 404 page shows up accessing config.yml if you are on a non standard port it needs to be $HTTP["host"] == "example.com:8080" { as well as "rewrite_url: true" in config.yml

I usually use apache but in this case I am forced using lighttpd. thanks for the help, I appreciate it, I tried for two weeks to get this to work. LOL

PhrozenByte commented 6 years ago

Yeah, it seems like the only easy-to-configure webserver is Apache, but Apache has the disadvantage of a comparable bad performance... Anyway, it works, this is what counts 😆 Thanks for testing! 👍

#edit: Done, see 9c182bd

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1: