Make Anchor CMS work with its files elsewhere

Recently I wanted to tidy up my public_html directory - as the folders were getting too much and I like a clean directory.

My site uses a beautifully simple CMS called Anchor which relys the following file structure to work:


What I wanted to do was combine all of the folders into one place. I decided that place would be a folder called components. I wanted to achieve this without changing any base URLs with minimum work. After some hit and miss testing it turned out to be a fairly easy process. This would work with any folder structure - however, I would avoid calling your folder any of the names already used.

Unfortunately, all the folders need to be publicly accessible due to various CSS and JS assets required.

1. Move the folders into the components folder

Your file system should now look like:


2. Update Line 29 of index.php

Add the name of your sub folder to the PATH constant:

define('PATH', dirname(__FILE__) . DS . 'components' . DS);

Anchor uses this PATH for loading various aspects of the site.

3. Add the following lines to your .htaccess file

The lines below spoof the browser into thinking files are where they are not. The [L] tells apache to apply that rewrite rule - read more on the apache website. I haven;t used a 301 redirect as I still want the browser to believe the assets are at the unmodified path.

RewriteRule ^anchor/(.*)$ /components/anchor/$1 [L]
RewriteRule ^content/(.*)$ /components/content/$1 [L]
RewriteRule ^system/(.*)$ /components/system/$1 [L]
RewriteRule ^themes/(.*)$ /components/themes/$1 [L]

This should be placed near the top of your .htaccess file.

4. (Bonus) Remove index.php from the URL structure

By default, Anchor requires index.php to be in the URL path (e.g. - to remove this, add the below to your .htaccess - there are more details in the AnchorCMS Documentation

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?/$1 [L]
This website is currently having a full content audit - apologies if some of the code or content looks a bit funky!

View this post on Gitlab

You might also enjoy…

  • Advanced Gulp File

    Posted on 22nd May 2014.

    With gulp starting to find itself into my everyday workflow - I've started to understand its quirks and twists, and how to get along with it. This is an advancement on my original gulpfile from a few months ago

Mike Street

Written by Mike Street

Mike is a front-end developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Twitter.