Htaccess Redirect Errors With OpenLiteSpeed (OLS) Rewrite Rules

Hi everyone.

I installed CyberPanel and moved my site. I was using RedirectMatch with my links that changed.

But with OLS rewrite rules I cant use this. Is not there RedirectMatch on OLS? Or may I do some changes on codes.

I was using this codes for redirecting main extension and all sub extensions with any cpanel hostings.

RedirectMatch abc/(.+) https://your-domain.com/def/$1 [R=301,L]
RedirectMatch abc/$ https://your-domain.com/def/ [R=301,L]

With this codes I could redirect “abc link” to “def” and automatically all “abc sub extensions” to “def sub extensions”.

For example:

/abc => /def
/abc/a => /def/a
/abc/a/b => /def/a/b

But with CyberPanel and OLS RedirectMatch is not working for me. I always take search console errors with 404 about changed and not redirected links.

On OpenLiteSpeed forum I saw a RewriteRule redirect like this:
(RewriteRule phpinfo.php /2/phpinfo.php) but this is not working, too.

Google Bots started to go back to the old links - extensions. So redirects are not working no longer.

Thanks.

This will work


RewriteRule /abc/(.+) https://your-domain.com/def/$1 [R=301,L]
RewriteRule /abc/$ https://your-domain.com/def/ [R=301,L]

@usmannasir said:
This will work


> RewriteRule /abc/(.+) https://your-domain.com/def/$1 [R=301,L]
> RewriteRule /abc/$ https://your-domain.com/def/ [R=301,L]
> 

Thanks for reply but it is not working Usman Nasir.

Create ticket.

@usmannasir said:
Create ticket.

Hi Usman Nasir.

I created a ticket and ID: P6M-L7D-WSPR

RewriteRule /uncategorized/(.+) https://domain.com/$1 [R=301,L]
RewriteRule /uncategorized$ https://domain.com/ [R=301,L]

You need to put these rules below LSCache block and before WordPress rules.

@usmannasir said:

RewriteRule /uncategorized/(.+) https://domain.com/$1 [R=301,L]
> RewriteRule /uncategorized$ https://domain.com/ [R=301,L]

You need to put these rules below LSCache block and before WordPress rules.

So thanks Usman Nasir.

You saved me from a big trouble. Did you do any other change? I used this codes and they did not work before, as far as I remember.

Also I added this codes at the bottom of the htacces, by mistake. But they worked, too :slight_smile:

@ahmet said:

@usmannasir said:

RewriteRule /uncategorized/(.+) https://domain.com/$1 [R=301,L]
> > RewriteRule /uncategorized$ https://domain.com/ [R=301,L]

You need to put these rules below LSCache block and before WordPress rules.

So thanks Usman Nasir.

You saved me from a big trouble. Did you do any other change? I used this codes and they did not work before, as far as I remember.

Also I added this codes at the bottom of the htacces, by mistake. But they worked, too :slight_smile:

Have not made any other changes.

Edit: The Rewriterule codes should be added like Usman Nasir says, after LSCache and before WordPress rules. Otherwise the redirect is not working.

Thanks.

Good day! Please I need Help
I know this discussion is a bit stale, but since it’s the only one I found while searching - it’s possible this is what others get to see.
I tried the above method but it isn’t working for me. I found that using RewriteRule ^/?listing/(.*)$ https://www.def.com/listing/$1 [R=301,L] is more correct with openlitespeed from here
Rewrite rule difference in .htaccess vs VH rewrite tab vs VH context rewrite rules – OpenLiteSpeed

Unfortunately, redirect still isn’t working. What am I missing?
The main Site is MU subdomain

Good day! Please I need Help I know this discussion is a bit stale, but since it's the only one I found while searching - it's possible this is what others get to see. I tried the above method but it isn't working for me. I found that using RewriteRule ^/?listing/(.*)$ https://www.def.com/listing/$1 [R=301,L] is more correct with openlitespeed from here https://openlitespeed.org/kb/migrate-apache-rewrite-rules-to-openlitespeed/

Unfortunately, redirect still isn’t working. What am I missing?
The main Site is MU subdomain

It seems I was a bit hasty, It’s working now - flawlessly. (Seems I needed to restart Litespeed)

After a big time I took a Redirect error again. I solved my problem with Hostephen’s advice and I want to update for others that taking error. As Hostephen said now this is working with a bit change for me. Anyone can try this three forms.

Before (At the past it worked but now not)

RewriteRule /aaaaa/(.+) https://your-domain.com/bbbbb/$1 [R=301,L]
RewriteRule /aaaaa/$ https://your-domain.com/bbbbb/ [R=301,L]

After (At the past not tried but now working)

RewriteRule ^/?aaaaa/(.+) https://your-domain.com/bbbbb/$1 [R=301,L]
RewriteRule ^/?aaaaa/$ https://your-domain.com/bbbbb/ [R=301,L]

Or this form (If not works above two option you can try this, I do not try this form at all)

RewriteRule ^/?aaaaa/(.*)$ https://your-domain.com/bbbbb/$1 [R=301,L]

NOTE: Do not forget to reload OpenLiteSpeed and LiteSpeed services from your CyberPanel/ServerStatus tab after any change.

Do they need also

(rules here)

… In order to work?

I haven’t make this work in an .hatcess file (inside public_html folder, wordpress)

Also. Can the redirection be to an external URL? As usual? Because I’m sort of pissed of this isn’t working. So many hours with this, and yet here we are…