Hostinger/LiteSpeed: what .htaccess to use? Getting 403 error after fresh install

Your software
My Mautic version is: 5.04
My PHP version is: 8.2
My Database type and version is: MySQL 5

Your problem
My problem is:

  • after fresh install of Mautic on Hostinger.com (a LiteSpeed server), I am getting 403 server error when I try to continue installation.

These errors are showing in the log:

Steps I have tried to fix the problem:

  • I have commented-out the following section in .htaccess file, which allowed me to finish installation:

<IfModule authz_core_module>

  • But then files like ie. /config/local.php are no longer restricted from access in browser.

  • What should I use for .htaccess on a LiteSpeed server to protect the internale files?

  • ChatGPT rewrote the .htaccess as the following, will this be sufficient?

# Use the front controller as index file
DirectoryIndex index.php

# Set Authorization header for OAuth2 for when PHP is running under fcgi
RewriteCond %{HTTP:Authorization} .+
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

# Redirect to URI without front controller to prevent duplicate content
RewriteCond %{REQUEST_URI} ^/index\.php(/(.*)|$)
RewriteRule ^index\.php(/(.*)|$) /$2 [R=301,L]

# If the requested filename exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule . - [L]

# Rewrite all other queries to the front controller.
RewriteRule . /index.php [L]

# Deny access to PHP files directly
<FilesMatch "\.php$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Deny access to composer files
<FilesMatch "^(composer\.json|composer\.lock)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Allow access to specific files
<FilesMatch "^(index\.php|upgrade/upgrade\.php)$">
    Order Allow,Deny
    Allow from all
</FilesMatch>

# Compression settings (LiteSpeed handles this natively)
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE text/css
    # Other types can be added here
</IfModule>
1 Like

A 403 Forbidden error is usually a result of a web server restriction.

You need to look into rules like the Order Allow,Deny within the <FilesMatch "\.php$"> found in your .htaccess.

Also check your files&folders permissions, litespeed configuration et al.