URL Canonicalization

Chris D

XenForo developer
Staff member
Ok.

URL Canonicalization I believe is where you can force (for example) the non WWW version of your URL to redirect to the WWW version of your URL. Or viceversa. In fact, here it is viceversa and www.xenforo.com redirects to xenforo.com.

I believe XenForo does this automagically via this code:

<link rel="canonical" href="http://xenforo.com/community/" />

And on my site, ValveTime.net:

<link rel="canonical" href="http://www.valvetime.net/forum/" />


However, for us it doesn't seem to be working.

What might I be missing?

I've even added some recommended rewrites into the .htaccess and it still doesn't work.

Effectively, http://www.valvetime.net is different to valvetime.net.
 
Add these two lines to your XenForo .htaccess file:

Rich (BB 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 500 default

<IfModule mod_rewrite.c>
	RewriteEngine On

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

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

That will force all forum URLs to use "www".
 
I'm sat here, trying to work out why that - which is exactly what I did yesterday - wasn't working. Or more importantly, why my .htaccess file was missing entirely.

I'm either going mad or... yes... I'm going mad.

Well that is working :D

Thanks Jake :)

Now... any particular reason why Xenforo.com loses the www. rather than forcing it? Is there any SEO benefits to either method?
 
I'm sat here, trying to work out why that - which is exactly what I did yesterday - wasn't working. Or more importantly, why my .htaccess file was missing entirely.

I'm either going mad or... yes... I'm going mad.

Well that is working :D

Thanks Jake :)

Now... any particular reason why Xenforo.com loses the www. rather than forcing it? Is there any SEO benefits to either method?

Have you gone mad? I'm afraid so. You're entirely bonkers. But I'll tell you a secret. All the best people are. :)

Don't feel bad. I forget small little things all the time. I spent over 2 hours trying to figure out why something I was working on wasn't working at all and it turned out all I was missing was this ;

That small, simple, and easy to notice things completely blinded me for 2 hours. (FYI: If you think it was the symbol above, you're wrong. It was the space before it I was missing)
 
Top Bottom