picocms / Pico

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

Content *and* assets outside of document root #423

Closed tanghus closed 6 years ago

tanghus commented 6 years ago

I have Pico installed in my document root but content in another directory, one level up.

In config/config.php I have

$config['rewrite_url'] = true;
$config['content_dir'] = '../my/content/';  // Content directory

My .htaccess in web root:

# BEGIN Pico CMS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteEngine on
# Always use https://example.com (domain is changed from my own)
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

# Externally  redirect from /?page to /page
RewriteCond %{THE_REQUEST} /\?([^\s]+) [NC]
RewriteRule ^/?$ /%1? [L,R]

# Internally map /page to /?page
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.+)$ /?$1 [L]
</IfModule>
# END Pico CMS

I can now access content just fine, but I can't access assets.

My site is on a shared web hosting to which I don't have shell access.

I'm using Pico 1.0.6.

Any idea what - probably obvious, if you know it - I have done wrong?

PhrozenByte commented 6 years ago

If you've installed Pico to the document root (e.g. /var/www/example.com/), then is ../my/content (i.e. /var/www/example.com/../my/content --> /var/www/my/content/) outside your document root and thus not part of your Virtual host. Thus you'll have to use a different domain/subdomain to access your assets. Pico generally shouldn't have any problem using a content directory outside your document root, as long as PHP doesn't prevent Pico from accessing the files (due to a open_basedir restriction for instance).

tanghus commented 6 years ago

Thanks for the fast reply :smiley: I've now set up a subdomain - assets.example.com - in which I will keep the same structure as the content. Sadly I don't have access to create subdomains outside of my allotted web-space, as I was hoping to also manage the assets in my Nextcloud instance, but this will do finely for now.