Some help with rewrite rules

#1
Hi

I'm struggling with these rules that I moved from apache (.htaccess) to OLS (vhost static context "/").

The last rule that works is: "RewriteCond %{HTTPS} off [OR]".
After that, no other rule works and I get 404 errors

What am I doing wrong?

Thanks

Code:
RewriteEngine On

# Cache
RewriteCond %{HTTP_COOKIE} !(xf_lscxf_logged_in|xf_user|xf_session_admin) [NC]
RewriteCond %{REQUEST_URI} !/install/ [NC]
RewriteRule .* - [E=Cache-Control:max-age=360,E="cache-vary:xf_style_id,xf_language_id"]

# No Cache
RewriteCond %{HTTP_COOKIE} (xf_lscxf_logged_in|xf_user|xf_session_admin) [NC]
RewriteRule .* - [E=Cache-Control:vary=loggedin,E=Cache-Control:no-cache]

# Xenforo
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

# Rewrite https and www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

# vBseo -> IPB
RewriteRule ^forum/f[\d]+/.+-([\d]+)/index([\d]+).html$ /forum/showthread.php?t=$1&page=$2 [L,R=301]
RewriteRule ^forum/f[\d]+/.+-([\d]+)/?$ /forum/showthread.php?t=$1 [L,R=301]
RewriteRule ^forum/f[\d]+/.+-([\d]+)-post[\d]+/?$ /forum/showthread.php?t=$1 [L,R=301]
RewriteRule ^forum/f([\d]+)/index([\d]+).html$ /forum/forumdisplay.php?f=$1&page=$2 [L,R=301]
RewriteRule ^forum/f([\d]+)/$ /forum/forumdisplay.php?f=$1 [L,R=301]
RewriteRule ^forum/$ / [L,R=301]
RewriteRule ^galeria/$ /media/ [L,R=301]
# /vBseo -> IPB

# IPB -> XF
RewriteRule ^forum/(\d+)-(.+)/page-(\d+) /forums/$2.$1/page-$3? [L,R=301]
RewriteRule ^forum/(\d+)-([^\/]*) /forums/$2.$1/? [L,R=301]
RewriteRule ^topic/(\d+)-(.+)/page-(\d+) /threads/$2.$1/page-$3? [L,R=301]
RewriteRule ^topic/(\d+)-([^\/]*) /threads/$2.$1/? [L,R=301]
RewriteRule ^gallery/category/(\d+)-([^\/]*) /media/categories/$2.$1/? [L,R=301]
RewriteRule ^gallery/album/(\d+)-([^\/]*) /media/albums/$2.$1/? [L,R=301]
RewriteRule ^gallery/image/(\d+)-([^\/]*) /media/$2.$1/? [L,R=301]
RewriteRule ^gallery /media/? [L,R=301]
RewriteRule ^user/(\d+)-([^\/]*) /members/$2.$1/? [L,R=301]
RewriteRule ^(blogs|blog) /? [L,R=301]
# /IPB -> XF

# Local rewrite rules
RewriteRule ^go/regras /help/rules [L,R=301]
RewriteRule ^go/termos /help/terms [L,R=301]
RewriteRule ^go/privacidade /help/privacy-policy [L,R=301]
RewriteRule ^go/fotos /threads/colocar-fotos-nas-mensagens.165/ [L,R=301]
RewriteRule ^go/videos /threads/colocar-videos-nas-mensagens.260/ [L,R=301]
# /Local rewrite rules
 
#2
RewriteRule with L flag - means LAST rule

after rule with L flag no any rules executed.

if you want execute rules in groups then you must each group "separate" by
<IfModule LiteSpeed>
....
</IfModule>
tags
 
#3
Thanks

The order rules are important too, but this one I can't get this to work... I need to redirect to HTTPS and to WWW.
The redirect to HTTPS is working, but to WWW doesn't work, either with HTTPS or a standalone rule.

Code:
<IfModule mod_rewrite.c>
  # Rewrite https and www
  RewriteCond %{HTTPS} off [OR]
  RewriteCond %{HTTP_HOST} !^www.
  RewriteRule (.*) https://www.example.com/$1 [L,R=301]
</IfModule>
What is wrong with this rule?
 
#5
@LiteCache this rule works, but needs to be placed before the last one.

Code:
# Rewrite to https and www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
This is the order that worked for me:

Code:
<IfModule LiteSpeed>
# Cache
RewriteCond %{HTTP_COOKIE} !(xf_lscxf_logged_in|xf_user|xf_session_admin) [NC]
RewriteCond %{REQUEST_URI} !/install/ [NC]
RewriteRule .* - [E=Cache-Control:max-age=360,E="cache-vary:xf_style_id,xf_language_id"]

# No Cache
RewriteCond %{HTTP_COOKIE} (xf_lscxf_logged_in|xf_user|xf_session_admin) [NC]
RewriteRule .* - [E=Cache-Control:vary=loggedin,E=Cache-Control:no-cache]
</IfModule>

<IfModule mod_rewrite.c>
# vBseo -> IPB
RewriteRule ^forum/f[\d]+/.+-([\d]+)/index([\d]+).html$ /forum/showthread.php?t=$1&page=$2 [L,R=301]
RewriteRule ^forum/f[\d]+/.+-([\d]+)/?$ /forum/showthread.php?t=$1 [L,R=301]
RewriteRule ^forum/f[\d]+/.+-([\d]+)-post[\d]+/?$ /forum/showthread.php?t=$1 [L,R=301]
RewriteRule ^forum/f([\d]+)/index([\d]+).html$ /forum/forumdisplay.php?f=$1&page=$2 [L,R=301]
RewriteRule ^forum/f([\d]+)/$ /forum/forumdisplay.php?f=$1 [L,R=301]
RewriteRule ^forum/$ / [L,R=301]
RewriteRule ^galeria/$ /media/ [L,R=301]
# /vBseo -> IPB

# IPB -> XF
RewriteRule ^forum/(\d+)-(.+)/page-(\d+) /forums/$2.$1/page-$3? [L,R=301]
RewriteRule ^forum/(\d+)-([^\/]*) /forums/$2.$1/? [L,R=301]
RewriteRule ^topic/(\d+)-(.+)/page-(\d+) /threads/$2.$1/page-$3? [L,R=301]
RewriteRule ^topic/(\d+)-([^\/]*) /threads/$2.$1/? [L,R=301]
RewriteRule ^gallery/category/(\d+)-([^\/]*) /media/categories/$2.$1/? [L,R=301]
RewriteRule ^gallery/album/(\d+)-([^\/]*) /media/albums/$2.$1/? [L,R=301]
RewriteRule ^gallery/image/(\d+)-([^\/]*) /media/$2.$1/? [L,R=301]
RewriteRule ^gallery /media/? [L,R=301]
RewriteRule ^user/(\d+)-([^\/]*) /members/$2.$1/? [L,R=301]
RewriteRule ^(blogs|blog) /? [L,R=301]
# /IPB -> XF

# Local rewrite rules
RewriteRule ^go/regras /help/rules [L,R=301]
RewriteRule ^go/termos /help/terms [L,R=301]
RewriteRule ^go/privacidade /help/privacy-policy [L,R=301]
RewriteRule ^go/fotos /threads/colocar-fotos-nas-mensagens.165/ [L,R=301]
RewriteRule ^go/videos /threads/colocar-videos-nas-mensagens.260/ [L,R=301]
# /Local rewrite rules

# XF Deny rules
RewriteRule ^src/.*$ - [F,L]
RewriteRule ^library/.*$ - [F,L]
# / XF Deny rules
</IfModule>

<IfModule mod_rewrite.c>
# Rewrite to https and www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
</IfModule>

<IfModule mod_rewrite.c>
# Xenforo
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
 
Top