XF 1.4 .htaccess redirect

el canadiano

Active member
Recall that the default XenForo's .htaccess looks like this.

Code:
#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
    RewriteEngine On
    Options +FollowSymlinks -MultiViews

    #    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
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>

Given my domain is https://rockbandforums.com, I want to extend my .htaccess so that it does the following.
Now, the third bullet point is impossible because my key is only valid for rockbandforums.com without the www. Therefore, we will ignore the last point.

Now, here's my issue. I have the following code which satisfies the first two points.

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

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

From what I have tested, if I were to place this after XenForo's conditions, this will not work at all. If I place it before, then it will work. However, XenForo's friendly URLs feature (which is currently turned on) will break.

Is there a way where I can rewrite my .htaccess such that it will work with both the friendly URLs and get that to write?
 
I would note that the first rule would actually match your 1st and 3rd bullet points. The second rule is what handles the 2nd point.

Conceptually, the rules are ok, but this line is wrong:
Code:
RewriteCond %{HTTP_HOST} !^www\.rockbandforums\.com$
I believe it should be:
Code:
RewriteCond %{HTTP_HOST} !^rockbandforums\.com$
You need to enter the host that you want to be the canonical version.

These rules need to go before the default XF rules as the last XF rule is a catch-all.
 
I would note that the first rule would actually match your 1st and 3rd bullet points. The second rule is what handles the 2nd point.

Conceptually, the rules are ok, but this line is wrong:
Code:
RewriteCond %{HTTP_HOST} !^www\.rockbandforums\.com$
I believe it should be:
Code:
RewriteCond %{HTTP_HOST} !^rockbandforums\.com$
You need to enter the host that you want to be the canonical version.

These rules need to go before the default XF rules as the last XF rule is a catch-all.

Brilliant as you once was when I last used the software. Correct me if I'm wrong, but your updated cond is saying if it isn't rockbandforums.com? I've been using nginx the last little while and this is the first time back on Litespeed.
 
Top Bottom