Redirect non-www to www and https using Redirect permanent

#1
Hi,

I'm trying to redirect everything from non-www to www and using https, for example:
example.com to https://www.example.com
www.example to https://www.example.com

I'm doing the changes in Configuration / Virtual Hosts / Rewrite

This works:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

However, I want to use Redirect permanent
So I tried:
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://www.example.com/

Unfortunately, I got www.example.com redirected you too many times.

I read https://www.litespeedtech.com/support/forum/threads/rewrite-problem.3491/#post-17355 and it seems it might be a bug, is there a way to use Redirect permanent in Configuration / Virtual Hosts / Rewrite to make it work?

Thank you!
 

NiteWave

Administrator
#4
if you redirect to other domain,
Redirect permanent / https://www.other.com/
it'll work well.

however, if you redirect to same domain, it'll cause infinite redirect loop as you've experienced.
since it just redirect to itself.

to user Redirect correctly, you have to set source URI different with target URI.
so
Redirect permanent /abc https://www.other.com/xyz
will work as expected
 
Top