[Fixed] htaccess RewriteRule migration from Apache to LiteSpeed Enterprise on Cloudlinux Cpanel

#1
Hi all,

My first post here and hoping this will lead to a helpful result for many who are adopting LiteSpeed Enterprise on Cloudlinux Cpanel from Apache with an existing website with RewriteRule in Htaccess file in public_html.

So I installed LiteSpeed Enterprise and tried to get the below htaccess rules working. I have edited this down for privacy and also included only one type for each rule in the below example.

HTAccess rules - unchanged from apache start

Options +FollowSymLinks
RewriteEngine on

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^/?$ "https\:\/\/www\.domain\.com\/" [R=301,L]
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "www.staticdomain.co.uk"
</IfModule>
RewriteRule ^.well-known/apple-app-site-association$ .well-known/apple-app-site-association.p7c [L]

RewriteRule ^oldfilepath?$ https://www.domain.com/newfilepath [R=301,L]

RewriteRule ^newfilepath/?$ oldfilepath.php [NC,L]

RewriteRule ^newfilepath/([^/]+)/([^/]+)/?$ oldfilepath.php?variable1=$1&variable2=$2&variable3=1 [L,QSA]

RewriteRule ^newfilepath$ /oldfilepath.php? [L]

RewriteRule ^newfilepath$ /oldfilepath.php?

<filesMatch ".(ico|jpg|jpeg|png|gif|webp|woff|woff2)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>
<filesMatch ".(css|js|scss)$">
Header set Cache-Control "max-age=31536000, public"
</filesMatch>

HTAccess rules - unchanged from apache end

I have read that the below

RewriteRule ^oldfilepath?$ https://www.domain.com/newfilepath [R=301,L]

should be amended to the below adding a / before the ^

RewriteRule ^/oldfilepath?$ https://www.domain.com/newfilepath [R=301,L]


I think I am also missing something with the below?

Options +FollowSymLinks
RewriteEngine on

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^/?$ "https\:\/\/www\.domain\.com\/" [R=301,L]


Any and all help is so appreciated!
 

NiteWave

Administrator
#2
I have read that the below

RewriteRule ^oldfilepath?$ https://www.domain.com/newfilepath [R=301,L]

should be amended to the below adding a / before the ^

RewriteRule ^/oldfilepath?$ https://www.domain.com/newfilepath [R=301,L]
no. no need modify.

the modify is only needed when you move the rule from .htaccess to virtual host, for both apache and litespeed.
please refer https://httpd.apache.org/docs/current/howto/htaccess.html#rewrite

So I installed LiteSpeed Enterprise and tried to get the below htaccess rules working.
any rule not working yet ?
I have edited this down for privacy and also included only one type for each rule in the below example.
looks still left one line starting with "Header set Access-Control-Allow-Origin" ?
 
#3
Thank you @NiteWave

i am pleased to say the issue is fixed and it came from Cpanel Support as I purchased the enterprise licence of Litespeed from them.

In summary it is this...

I've modified the rule for the channels URL so that it is compatible with both LiteSpeed and Apache, and I've left the original version of the rule in a comment so that you can compare:

The following is compatible with both Apache and LiteSpeedstyle
RewriteRule ^channels$ /topics/?

# The following is only compatible with Apache
#RewriteRule ^channels$ /topics?

If you switch to LiteSpeed you'll see that adding the / character to the end of the substitution makes the rewrite work.

I believe it has something to do with the way that the topics url is defined:

RewriteRule ^topics/?$ pages/topics/topics.php

Sometimes there are very subtle differences in the way that LiteSpeed and Apache process rewrites.

Amending this thread to fixed in case it helps anyone else in this great community! :)
 
Top