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

XF 1.4 Xenforo and Wordpress friendly force WWW in URL?

WoodiE

Well-known member
#1
On one of my XF sites I have wordpress installed on the root directory and xenforo installed in the /forums folder. What I'd like to do is to force all non-www traffic to include the www prefix. Right now it only kind of works, if I go to MYDOMAIN.com it redirects to www.MYDOMAIN.com, so far so good.

But if I go to MYDOMAIN.com/forum it redirects me to the main page, which I can then click on the forum link in the menu (www included) and the forum loads. However I'm not able to just type MYDOMAIN.com/forum and it redirects to www.MYDOMAIN.com/forum

Here is the root .htaccess file
Code:
<FILES .htaccess>
order allow,deny
deny from all
</FILES>
##
#         FORCE NON-WWW to WWW URLS
RewriteEngine On
RewriteCond %{HTTP_HOST} ^MYDOMAIN.com
RewriteRule (.*) http://www.MYDOMAIN.com/$1 [R=301,L]
#         DISALLOW DIRECTORY BROWSING
Options ALL -Indexes
##
#         ENABLE GZIP COMPRESSION
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</IfModule>
##
#        EXPIRES CACHING
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
##
#        PHPBAY START
<IfModule mod_rewrite.c>
# this goes above ANY Wordpress htaccess code in the .htaccess file
# if your site is installed in a folder, ie: http://www.yoursite.com/folder/
# add the folder to name to the RewriteBase line, ie: RewriteBase /folder/
RewriteBase /
RewriteRule ^media/1/images/e/(.*)$ http://thumbs.ebaystatic.com/pict/$1 [R,L]
RewriteRule ^media/1/images/f/(.*)$ wp-content/plugins/phpBay/media/images/$1 [R,L]
RewriteRule ^media/1/css/(.*)$ wp-content/plugins/phpBay/media/css/$1 [R,L]
RewriteRule ^watch-list-(.*)_(.*)_(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&campaignid=$5&linktype=watch&mode=debug [R,L]
RewriteRule ^watch-list-(.*)_(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&linktype=watch&mode=debug [R,L]
RewriteRule ^watch-list-(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&linktype=watch&mode=debug [R,L]
RewriteRule ^watch-list-(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&linktype=watch&mode=debug [R,L]
RewriteRule ^watch-list-(.*)_(.*)_(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&campaignid=$5&linktype=watch [R,L]
RewriteRule ^watch-list-(.*)_(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&linktype=watch [R,L]
RewriteRule ^watch-list-(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&linktype=watch [R,L]
RewriteRule ^watch-list-(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&linktype=watch [R,L]
RewriteRule ^bid-(.*)_(.*)_(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&campaignid=$5&mode=debug [R,L]
RewriteRule ^bid-(.*)_(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&mode=debug [R,L]
RewriteRule ^bid-(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&mode=debug [R,L]
RewriteRule ^bid-(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&mode=debug [R,L]
RewriteRule ^bid-(.*)_(.*)_(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&campaignid=$5 [R,L]
RewriteRule ^bid-(.*)_(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4 [R,L]
RewriteRule ^bid-(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3 [R,L]
RewriteRule ^bid-(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2 [R,L]
RewriteRule ^bin-(.*)_(.*)_(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&campaignid=$5&mode=debug [R,L]
RewriteRule ^bin-(.*)_(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&mode=debug [R,L]
RewriteRule ^bin-(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&mode=debug [R,L]
RewriteRule ^bin-(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&mode=debug [R,L]
RewriteRule ^bin-(.*)_(.*)_(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&campaignid=$5 [R,L]
RewriteRule ^bin-(.*)_(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4 [R,L]
RewriteRule ^bin-(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3 [R,L]
RewriteRule ^bin-(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2 [R,L]
RewriteRule ^item-(.*)_(.*)_(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&campaignid=$5&mode=debug [R,L]
RewriteRule ^item-(.*)_(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&mode=debug [R,L]
RewriteRule ^item-(.*)_(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&mode=debug [R,L]
RewriteRule ^item-(.*)_(.*)_debug.html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&mode=debug [R,L]
RewriteRule ^item-(.*)_(.*)_(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4&campaignid=$5 [R,L]
RewriteRule ^item-(.*)_(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3&ccid=$4 [R,L]
RewriteRule ^item-(.*)_(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2&country=$3 [R,L]
RewriteRule ^item-(.*)_(.*).html$ wp-content/plugins/phpBay/auction.php?title=$1&item=$2 [R,L]
</IfModule>
#        PHPBAY END
##
#        FILTER PHP SCRIPT INJECTIONS
#Options +FollowSymLinks
#RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
#RewriteRule ^(.*)$ index.php [F,L]
##
#        WORDPRESS START
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#        WORDPRESS END
And this is the htaccess file from my Xenforo forum.

Code:
# PREVENT VIEWING OF .HTACCESS
<Files .htaccess>
    Order deny,allow
    Deny from all
</Files>
#
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^MYDOMAIN\.com
RewriteRule (.*) http://www.MYDOMAIN.com/$1 [R=301,L]
</IfModule>
#
<IfModule mod_rewrite.c>
    # RewriteEngine On

    #    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 /forum

    #    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>
If I remove the redirect bit from my /forum htaccess file the forum is then accessible from either www or non-www.

Any suggestions would be much appreciated!
 

Jake Bunce

XenForo moderator
Staff member
#2
Amendment to your XF .htaccess:

Code:
# PREVENT VIEWING OF .HTACCESS
<Files .htaccess>
    Order deny,allow
    Deny from all
</Files>
#
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^MYDOMAIN\.com
RewriteRule (.*) http://www.MYDOMAIN.com/forum/$1 [R=301,L]
</IfModule>
#
<IfModule mod_rewrite.c>
    # RewriteEngine On

    #    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 /forum

    #    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>
Also, is XF in /forum or /forums? You said /forums but then I see /forum as your RewriteBase. Make sure you use the correct directory.