CMS Made Simple does not change to subpage of PHP CMS

I’m trying to convert these .htaccess rules

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Rewrites urls in the form of /parent/child/grandchild but only rewrites if the requested URL is not a file or directory.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

In my current config, I have problem that when I go on , it does not change page content to that page, content is always at root url frontpage. {
        root ./public
        fastcgi / /var/run/php/php7.0-fpm.sock {
                ext     .php
                split   .php
                index   index.php

        rewrite {
                to {path} {path}/ /index.php?page={1}


I also did try this, but then only root url loaded, not subpages:

        rewrite {
               if {file} not favicon.ico
               r (/\/index.php?page=.*/)
               to /index.php?page={1}

Admin pages at /admin still work correctly.

Documentation about CMS Made Simple pretty URLs is here:

I have also added this line to CMS Made Simple’s config.php:

$config['url_rewriting'] = 'mod_rewrite';


rewrite {
    r ^(.+)$
    to {path} {path}/ /index.php?page={1}

I believe that without the capture group (the r subdirective), the placeholder {1} would have no data, so you’d be rewriting to /index.php?page= every time.

Incidentally, you can use the php preset to cut down your Caddyfile a little (see the fastcgi docs). Your fastcgi block would become a one liner:

fastcgi / /var/run/php/php7.0-fpm.sock php
1 Like


Thanks a lot, it works now!

I will submit solution to caddy examples.

1 Like

Feel free to mark my answer as the solution so others can find it easily when searching the forums :slight_smile:

1 Like


It actually occurs to me that a better option would probably be the following:

rewrite {
    to {path} {path}/ /index.php?page={uri_escaped}

This has a few benefits:

  • No regex
    (this is a big win if your server is ever under load)
  • Uses a placeholder to produce a query-escaped URI
    (should avoid instances where an unescaped URI might produce weird results)

Could you give that a try and let us know if it works as well?


Thanks, it works :slight_smile: I updated my pull request:

1 Like