Apache .htaccess works fine, 404 with Litespeed

.htaccesslitespeed

I'm using litespeed on shared hosting (unfortunately), and I'm trying to use .htaccess to rewrite http to https NON www – and change domain.com/index to domain.com/my-string for SEO purposes.

This is working fine in Apache, and I didn't know my shared host was using Litespeed. I use the same .htaccess on litespeed which results in a 404, despite my filename being correct.

Here is my htaccess:

DirectoryIndex my-string.php

Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /

RewriteRule ^$ my-string [L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteRule ^my-string$ /my-string.php [L]

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
  AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

The bottom section was added by my host.

This is working correctly in Apache, performs the 301 redirect from http non www, or http www to https non www with my string at the end of the URL, instead of index.

My understanding was litespeed uses the same syntax as Apache, so why is this happening?

Best Answer

The comments section is full so I'm linking my related answer:

https://serverfault.com/a/1083495/144798

To get local .htaccess working on Openlitespeed you first must generate those files AND then also point to those files within each virtual host AND ensure correct permissions. If you fail to do this, your websites might crash (fatal errors and/or 404 errors like this). Plus, you must reboot the Litespeed server every time you change .htaccess rules.

Related Topic