XF 1.5 Rewrite rule for https + www

abdfahim

Active member
#1
I want to forward all traffic to https, also want to keep session intact between www and non-www urls,

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{ENV:HTTPS} !on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    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>

Is it the right way? Also, why if I put that outside <IfModule mod_rewrite.c></IfModule> block?

Thanks
 
Last edited:

abdfahim

Active member
#3
Thanks Mike. I found and fixed some issues in my server, now it is working.

I also wanted to make sure if I put that code inside or outside <IfModule></IfModule> block.

Thanks for confirming.
 
Top