• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.4 Redirect Non-WWW to WWW with https

#1
Hi I am hosting my forum at subdir,

http://example.com/forum

I am using SSL on my domain,

Now i want to redirect non-www to www for my forum,
so redirect should be http://example.com/forum to https://www.example.com/forum


tried some settings posted on this forum, but i am getting error. Help please :)
Thank you.

Here is my part of code,


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# If you are having problems with the rewrite rules, remove the "#" from the
# line that begins "RewriteBase" below. You will also have to change the path
# of the rewrite to reflect the path to your XenForo installation.
#RewriteBase /xenforo

# This line may be needed to enable WebDAV editing with PHP as a CGI.
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
 

Jake Bunce

XenForo moderator
Staff member
#2
Add these rules to the top of the .htaccess file in your /forum directory:

Code:
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$
RewriteRule ^(.*)$ https://www.yoursite.com/forum/$1 [R=301,L]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yoursite.com/forum/$1 [R=301,L]