miniBB ®  
miniBB Support Forums
 | Forums | Register | Reply | Search | Statistics | Manual |
Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications /   

Permanent 301 redirect of ANY forum link from http://domain.any to http://www.domain.any

Author Paul
Lead Developer
#1 | Posted: 25 Jul 2007 08:19 | Edited by: Paul 
Most of you probably know that if somebody publish a link to your original domain without 'www', it will be probably displayed anyway. However it brings headache in the terms of SEO, since it could give you a "duplicated content" penalties from search crawler like Google.

(Despite I would disagree with this opinion...)

I have studied a lot of web pages regarding this subject, but most of them offer just a redirection using Apache's .htaccess. The code offered looks like:

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


Unfortunatelly I am not Apache guru and can not extend this code so it works correctly for all cases. What kind of cases? If you simply enter http://example.com/ it will work for you redirecting to http://www.example.com/. However if you enter http://example.com/somepage.html it will not redirect to that page properly (with 'www').

Here is the simple PHP code I've programmed to put on all miniBB pages. If you are using miniBB forums, you could use it at least for your forum script, forcing redirection of any kind of forum page which is accessed without 'www', to the original domain with 'www':

$site_url='http://www.minibb.com';

if(substr($_SERVER['HTTP_HOST'], 0, 4)!='www.' and substr($_SERVER['HTTP_HOST'], 0, 9)!='localhost') {
header("HTTP/1.1 301 Moved Permanently");
header("Location:{$site_url}{$_SERVER['REQUEST_URI']}");
exit;
}

This code needs to be pasted anywhere in setup_options.php.
Feel free to apply it for any other of your web site pages as well.
Don't forget to change $site_url value of course ;-)

Check how it works:

http://minibb.com/features.html
http://minibb.com/forums/9_0.html

Custom Tutorials and Modifications miniBB Support Forums / Custom Tutorials and Modifications / Permanent 301 redirect of ANY forum link from http://domain.any to http://www.domain.any Top
Your Reply Click this icon to move up to the quoted message
 Short link for this topic:

 ?
Only registered users are allowed to post here. Please, enter your username/password details upon posting a message, or register first.


Before posting, make sure your message is compliant with our forum posting rules. If not, it may be locked or deleted with no explanation.
 
miniBB Support Forums Powered by Forum Software miniBB ® Features  Requirements  Demo  Download  Showcase  Gallery of Arts
Compiler  Premium Extensions  Premium Support  License  Contacts
  Extend your miniBB-forums, attaching the images and files,
get the File and Picture Attachments add-on!
Galleries / Attachments Addon for miniBB