Active member
I am trying to force the use of http:// through my entire site, so that nobody can use www on the forum. This is important so that they can maintain their cookie when visiting another directory with another script... and have SSO

I tried a few approaches, different rewrite conditions, but none of them seem to be having any effect. Can someone please help me out here.

This is my .htaccess :

#    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
ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default
php_value file_uploads on
php_value upload_max_filesize 35971520
php_value post_max_size 35971520
php_value max_input_time 1000
php_value memory_limit 64M
php_value max_execution_time 1000
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
    #    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 %{HTTP_HOST} ^www\.website\.com$
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.website.com/community/$ [NC]
RewriteRule ^(.*)$ http://website.com/community/$1 [R=301,L]
    RewriteRule ^forum/(.*)$ http://website.com/community/$1 [R=301,L]
    RewriteRule ^(threads|forums|members|forum)/(.*)$ /community/$1/$2 [R=301,L]
    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]


Well-known member
On my forum I have my forum in a folder called /forums where Xenforo files are. So I have two .htaccess files. The .htaccess file similar to what you show in post #1 is located in the /forums folder.

In the folder where my domain is I have the following .htaccess file.

order deny,allow

RewriteEngine on

rewriterule ^index\.html$ / [r=301,nc]

rewritecond %{http_host} ^yourdomain.com [nc]
rewriterule ^(.*)$ http://yourdomain.com/$1 [r=301,nc]

This code would force the non-WWW in your domain name.


Well-known member
RewriteCond %{HTTP_HOST} ^www\.website\.com$
RewriteRule ^(.*)$ http://website.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.website.com/community/$ [NC]
RewriteRule ^(.*)$ http://website.com/community/$1 [R=301,L]

I sometimes have quirky results with .htaccess stuff, I think some hosts can be fussy.

I am not sure why in the above you have two different rewrites for what is essentially the same thing (ie. if the first one works, you don't need the second one)?

Also why in the first one you have used \ before the . but not anywhere else.

How about replacing the above two rules with just this, which seems to be the standard approach (and same as AndyB's):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

If that doesn't help, there are a couple of variations on Stack Exchange you might want to test:


Jake Bunce

XenForo moderator
Staff member
#2 to remove "www":


It's slightly different logic depending on what you want. My rule says, "if it's not yoursite.com then use yoursite.com".

Also why in the first one you have used \ before the . but not anywhere else.

Because that part is a regex where a period means "any character." By escaping it with a backslash it is treated as a literal period.



RewriteCond %{HTTP_HOST} ^www.website.com/community/$ [NC]


The HTTP_HOST does not include the directory name, only the domain portion of the URL.