PHP USUALLY CAN easily detect the "www" part in the address by checking HTTP_HOST or SERVER_NAME. It will be "yourdomain.com" without www and "ww
w.yourdomain.com" with ww
w.
But on 110mb (because of handling www part with an internal proxy) HTTP_HOST
never contains "www".
You can detect the IPs, but more easy is to use HTTP_VIA (or HTTP:VIA in .htaccess) - you can find it in many posts on this forum in technical section.
If you entering without "www" HTTP_VIA is empty (or have some value of other proxy if is in use by the client).
If you entering WITH "www" HTTP_VIA contains "
1.1 www.mysite.110mb.com" or "
1.1 www.mysite.911mb.com" or "
1.1 www.myextradomain.com".
PHPFor making this code as easy as possible and fit to all addresses (.110mb.com .911mb.com .extradomain) you can put this at the very beginning of your all pages:
if you want to force non-www address:www.yourextradomain.com -> yourextradomain.com
www.subdomain.110mb.com -> subdomain.110mb.com
www.subdomain.911mb.com -> subdomain.911mb.com(you don't have to edit anything)<?php
if (preg_match('/www\.'.$_SERVER['HTTP_HOST'].'/i', $_SERVER['HTTP_VIA']))
{ header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
?>
if you want to force with-www address:yourextradomain.com -> www.yourextradomain.com
subdomain.110mb.com -> www.subdomain.110mb.com
subdomain.911mb.com -> www.subdomain.911mb.com(you don't have to edit anything)<?php
if (!preg_match('/www\.'.$_SERVER['HTTP_HOST'].'/i', $_SERVER['HTTP_VIA']))
{ header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www." . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
exit();
}
?>
if you want to force only one non-www address (redirect 110mb subdomain to own domain in example):
www.yourextradomain.com -> yourextradomain.com
www.subdomain.110mb.com -> yourextradomain.com
subdomain.110mb.com -> yourextradomain.com
www.subdomain.911mb.com -> yourextradomain.com
subdomain.911mb.com -> yourextradomain.com(you have to edit your preferred domain - without www part in second line)<?php
$preferreddomain = 'ownextradomain.com'; // without www
if ($_SERVER['HTTP_HOST'] != $preferreddomain || preg_match('/www\.'.$preffereddomain.'/i', $_SERVER['HTTP_VIA']))
{ header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $preferreddomain . $_SERVER['REQUEST_URI']);
exit();
}
?>
if you want to force only one with-www address (redirect 110mb subdomain to own domain in example):
yourextradomain.com -> www.yourextradomain.com
subdomain.110mb.com -> www.yourextradomain.com
www.subdomain.110mb.com -> www.yourextradomain.com
subdomain.911mb.com -> www.yourextradomain.com
www.subdomain.911mb.com -> www.yourextradomain.com(you have to edit your preferred domain - without www part in second line)<?php
$preferreddomain = 'ownextradomain.com'; // without www
if ($_SERVER['HTTP_HOST'] != $preferreddomain && !preg_match('/www\.'.$preffereddomain.'/i', $_SERVER['HTTP_VIA']))
{ header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www." . $preferreddomain . $_SERVER['REQUEST_URI']);
exit();
}
?>
.htaccessFor doing the same with .htaccess (if you buy it here) - create file called ".htaccess" and upload it into your root folder on your account (or add this code to your existing .htaccess file):
(If you have any doubts - ask some .htaccess expert how to integrate your code.)if you want to force non-www address:www.yourextradomain.com -> yourextradomain.com
www.subdomain.110mb.com -> subdomain.110mb.com
www.subdomain.911mb.com -> subdomain.911mb.com(you have to edit names of your domain and 110mb subdomain - keep the syntax with backslashes!)Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:VIA} www\.yourdomain\.com$
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]
RewriteCond %{HTTP:VIA} www\.subdomain\.110mb\.com$
RewriteRule ^(.*)$ http://subdomain.110mb.com/$1 [R=301,L]
RewriteCond %{HTTP:VIA} www\.subdomain\.911mb\.com$
RewriteRule ^(.*)$ http://subdomain.911mb.com/$1 [R=301,L]
if you want to force with-www address:yourextradomain.com -> www.yourextradomain.com
subdomain.110mb.com -> www.subdomain.110mb.com
subdomain.911mb.com -> www.subdomain.911mb.com(you have to edit names of your domain and 110mb subdomain - keep the syntax with backslashes!)Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:VIA} !www\.yourdomain\.com$
RewriteCond %{HTTP_HOST} yourdomain\.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
RewriteCond %{HTTP:VIA} !www\.subdomain\.110mb\.com$
RewriteCond %{HTTP_HOST} subdomain\.110mb\.com$
RewriteRule ^(.*)$ http://www.subdomain.110mb.com/$1 [R=301,L]
RewriteCond %{HTTP:VIA} !www\.subdomain\.911mb\.com$
RewriteCond %{HTTP_HOST} subdomain\.911mb\.com$
RewriteRule ^(.*)$ http://www.subdomain.911mb.com/$1 [R=301,L]
if you want to force only one non-www address (redirect 110mb subdomain to own domain in example):
www.yourextradomain.com -> yourextradomain.com
www.subdomain.110mb.com -> yourextradomain.com
subdomain.110mb.com -> yourextradomain.com
www.subdomain.911mb.com -> yourextradomain.com
subdomain.911mb.com -> yourextradomain.com(you have to edit name of your domain - keep the syntax with backslashes!)Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:VIA} www\.yourdomain\.com$ [OR]
RewriteCond %{HTTP_HOST} !yourdomain\.com$
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]
if you want to force only one with-www address (redirect 110mb subdomain to own domain in example):
yourextradomain.com -> www.yourextradomain.com
subdomain.110mb.com -> www.yourextradomain.com
www.subdomain.110mb.com -> www.yourextradomain.com
subdomain.911mb.com -> www.yourextradomain.com
www.subdomain.911mb.com -> www.yourextradomain.com(you have to edit name of your domain - keep the syntax with backslashes!)Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:VIA} !www\.yourdomain\.com$ [OR]
RewriteCond %{HTTP_HOST} !yourdomain\.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
.htaccess simplifiedIf you care only about one domain (own or 110mb sub-) and don't care about other addresses (like 911mb subdomain).
if you want to force non-www address:(you have to edit name of your domain or 110mb subdomain - keep the syntax with backslashes!)Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:VIA} www\.yourdomain\.com$
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]
if you want to force with-www address:(you have to edit name of your domain or 110mb subdomain - keep the syntax with backslashes!)Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:VIA} !www\.yourdomain\.com$
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
NOTE: above codes are specific especially for 110mb servers configuration.These codes will not work correctly on other servers (your local in example) and vice versa - codes that works on other servers will not work correctly on 110mb servers with current configuration.
PS. Sorry, D3xt3r, that I am inputting my own three words, but I think using HTTP_VIA is more easy. With using IPs non-advanced users can ask - "what is my IP?". And sometimes (like box13 and box14) IP can change and handling www with proxy on 110mb probably will never change so HTTP_VIA will be the same.