Sometimes you might need to redirect a certain location in WordPress but you notice that irrespective of the code that you add, nothing happens. In this article, we offer you some pointers so that you can always add redirects.

Tip 1 - restart the OpenLiteSpeed service

After you alter your .htaccess make sure that you restart the OpenLiteSpeed service using the Bunnyshell interface:

  1. Go to Virtual Machines

  2. Select the VM where you wish to restart the service

  3. Select the Services tab

  4. Restart the OpenLiteSpeed service using the menu option (triple dot on the right)

Tip 2 - put the RewriteRule in the right place

Ensure that your place your redirect in the correct section. WordPress has it's own redirect code and the .htaccess file is parsed in an ordered fashion. The new rewrite rules should be above the # BEGIN WordPress Bunnyshell Config block or else the rewrite rules will never be executed.

Tip 3 - use the correct format

There are multiple ways to specify a rewrite rule, but the only format that can be used with the open-source version of LiteSpeed is to use a RewriteRule, not a Redirect 301.

The RewriteRule format is slightly more complex, therefore an example is provided below.

To redirect https://example.com/ordurl to https://example.com/newurl.php use:

RewriteRule ^oldurl/$ https://example.com/newurl.php [NC,L,R=301]

^ means that the URI starts with oldurl/

$ implies that the URI ends with the slash character

NC is a flag that does a case-insensitive match

L tells the engine to stop processing additional rules once it does this redirect for this request

R=301 implies that a 301 Redirect will be sent to the client

Did this answer your question?