.htaccesshttp-redirectmod-rewritehttp-status-code-301litespeed

Changing RedirectMatch to RewriteRule for OpenLiteSpeed


After changing the Wordpress Permalink structure, I was using RewriteMatch in the .htaccess file to create 301 redirects for all of the pages.

RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/([0-9]{2})/(?!page/)(.+)$ https://mywebsite.com/$4

I switched to OpenLiteSpeed recently and found that this no longer worked. Someone confirmed OLS ignores the RedirectMatch rule and advised switching to RewriteRule, so I used an htaccess tester tool and put the following together.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9]{4})/([0-9]{2})/([0-9]{2})/(?!page/) $4 [QSA,L]

I don't have much experience with writing rules, but the tool showed the correct output. After adding it to my .htaccess file however, it still doesn't work. I've restarted OLS but no changes.

I'm trying to figure out if there is something wrong with the rule (i.e. something incompatible with litespeed), or if this is related to the OLS web server?


Solution

  • Please try add this rule at top of your .htaccess

    RewriteRule ([0-9]{4})\/([0-9]{2})\/(.*) https://example.com/$3 [R=301,L]

    restart OLS after you added it.