L
L
levkus2018-09-18 13:34:22
CMS
levkus, 2018-09-18 13:34:22

How to write .htaccess for SPA and CMS (OctoberCMS)?

I've been using this .htaccess snippet floating around the web for quite a while now for my React projects:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.html [L]
</IfModule>

But now I have a task to make React SPA within October CMS. This CMS has a number of its own service routes (eg '/backend', '/storage') that I don't want to redirect to the index. I will also create several pages in the CMS itself that will return JSON data for the SPA (for example, '/api/works').
I want to set up .htaccess to send everything to index.php except what I specify in the exceptions.
How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
levkus, 2018-09-18
@levkus

If someone comes here looking for a similar solution specifically for OctoberCMS, then here it is:
Create a CMS page with url = /404.
In it we write:

function onStart()
{
    return Redirect::to('/');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question