Redirect 301 Issues

dsoneil

New Member
#1
Hello, I recently setup an OLS server (1.4.41) on Ubuntu 18.04 w/ LSPHP 7.2 running WordPress (WP) and it works great, however redirect 301's are causing me some headaches. Rewrite is enabled, and LSCache is installed on WP. It works fine and the rewrite to remove WP index,php is working. However, simple 301 redirects in my htaccess file do not work.

Basic settings in htaccess
RewriteEngine on
RewriteBase /

Example of an issue:
redirect 301 /old/file-name.php https://domain.com/new/file-name.php

This just produces a 404 error. Any file with a .php does not redirect.

If I try:
redirect 301 /old/file-name https://domain.com/new/file-name

If the file name and directory are close it seems to pattern match and redirect to a similar URL but not necessarily the one I want it to go to.

The directory I use for WP files is /home/aod/wp/

Error logs shows this:

[INFO] Tried to add new context: URI /2006/ location /home/aod/wp//2006/, result 0x5632e9eaffc0
[REWRITE] Source URI: '2006/06/alberta-premium-rye-whisky.php' => Result URI: '/index.php'
[INFO] Tried to add new context: URI /wp-admin/ location /home/aod/wp//wp-admin/, result 0x5632e9ec3e90

I can see the // in the uri but don't know where it is coming from.

The two example work fine in Apache 2.4. And it is important for me to maintain these redirects as this site has been around since 2005 (MoveableType days) and to maintain so of my Google rank for SEO purposes I need these links going to the right place. I'm hoping to move to OLS but this would be a deal breaker.

Thanks for any help. Cheers

Other Details:
Using the following for index.php removal in WP:
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
 

dsoneil

New Member
#3
Ok. In the meantime I've found another solution. Using Rewrite ^/ in the vitrualhost rules section works, but it has to be above the rules that remove index.php from WordPress url's.

RewriteRule ^/?index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
 

Pong

Administrator
#5
There are a few things:
1. rewrite rules in .htaccess and rewrite rules in the virtual host rewrite section are different.
You can simply use apache .htaccess rewrite rule, just need to create a "/" context and write rewrite rule there, or simply specify the rewrite file path as: "rewriteFile /file/path/to/.htaccess" at the "/" context "Rewrite Rules" area.

https://openlitespeed.org/kb/apache-rewrite-rules-in-openlitespeed/
https://openlitespeed.org/kb/migrate-apache-rewrite-rules-to-openlitespeed/

2. Only rewrite rules work in .htaccess with OpenLiteSpeed. "redirect 301" may not work with OpenLiteSpeed in .htaccess(it works with LiteSpeed EnterPrise). hence, you may use rewrite rules instead. For example:

RewriteEngine on
RewriteRule ^old/file-name.php https://domain.com/new/file-name [L,R=301]

3. Every time you make changes to .htaccess, you will need to restart OpenLiteSpeed to apply the changes. This is different to LiteSpeed Enterprise, and there is no restart required for LSWS when there is any changes in .htaccess.
 
Last edited:

dsoneil

New Member
#6
Thanks, very useful information and using RewriteRule will work for my purposes. The more I use OLS the more I like it. Cheers
 
#7
Hello, we have issues with 301 dirgeobiz.com to qkkk.co.uk -

IN VH HOST we used

rewrite {
RewriteCond %{HTTP_HOST} ^www.dirgeobiz.com
RewriteRule ^/(.*)$ http://qkkk.co.uk/$1 [L,R=301]
}
addDefaultCharset off

As Found here: https://openlitespeed.org/kb/migrate-apache-rewrite-rules-to-openlitespeed/


In .htaccess we used

RewriteEngine On
RewriteRule ^/([a-zA-Z0-9_-]+)$ https://qkkk.co.uk/$1/ [R=301,L]

As found here: https://openlitespeed.org/kb/apache-rewrite-rules-in-openlitespeed/

The both did not work..

Now we left both active. (but not working...)

Our rewrite in VH HOST is enabled.

rewrite {
enable 1
autoLoadHtaccess 1
}

Any help?

Thanks

John
 
Top