Results 26 to 47 of 47
-
01-28-2010, 01:34 AM #26Virtually Flawless ;)
- Join Date
- Apr 2009
- Location
- USA / UK
- Posts
- 4,577
→ RAM Host -- USA Premium & Budget Linux Hosting
█ Featuring Powerful cPanel Shared Hosting
█ & Premium Virtual Dedicated Servers
→ Follow us on Twitter
-
03-08-2010, 03:10 AM #27Newbie
- Join Date
- Aug 2007
- Posts
- 14
Thanks ;-)
-
03-15-2010, 01:42 AM #28Newbie
- Join Date
- Mar 2010
- Posts
- 13
Thanks for the tutorial
-
03-15-2010, 03:15 AM #29Temporarily Suspended
- Join Date
- Jan 2010
- Posts
- 40
Thanks for the tut, it's really helpful!
-
04-05-2010, 05:45 PM #30Newbie
- Join Date
- Nov 2009
- Posts
- 27
PHP Code:$domain = $_SERVER['SERVER_NAME'];
$pathinfo = $_SERVER['REQUEST_URI'];
if(eregi('www.',$domain)) {
$domain = ereg_replace('www.','',$domain);
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://'.$domain.$pathinfo);
}
-
04-05-2010, 06:41 PM #31Web Hosting Master
- Join Date
- Jan 2008
- Location
- St. John's, NL
- Posts
- 2,201
If you are using Apache as your web server, simply add the following to a .htaccess file in the same folder as your site pages
Replace example.com with your domain name.
Code:RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Cpanel/WHM • PHP • Perl • Ruby • Full Time Support
LCWSoft - Canada web hosting (based in Newfoundland) since 2007
Servers based in the US and Canada (Uptime Report)
-
04-05-2010, 06:52 PM #32Virtually Flawless ;)
- Join Date
- Apr 2009
- Location
- USA / UK
- Posts
- 4,577
Excellent advise.
However sending "HTTP/1.1 301 Moved Permanently" may not always work for a variety of reasons (apache vs something else, cgi vs fastcgi, linux vs windows, etc) -
eregi and excess variables are unnecessary (and ereg is depreciated anyway).
This is what I would use to ensure it all works as expected if you're using the PHP method:
PHP Code:if(strstr($_SERVER['SERVER_NAME'],'www.')!=false)
{
header('Location: http://'.str_replace('www.','',$_SERVER['SERVER_NAME']).$_SERVER['REQUEST_URI'],true,301);
}
Works with PHP 4.3.0+, PHP 5 (all, including 5.3.x), and PHP 6→ RAM Host -- USA Premium & Budget Linux Hosting
█ Featuring Powerful cPanel Shared Hosting
█ & Premium Virtual Dedicated Servers
→ Follow us on Twitter
-
04-05-2010, 07:05 PM #33Web Hosting Master
- Join Date
- Jan 2008
- Location
- St. John's, NL
- Posts
- 2,201
I see 20 PHP-based solutions, when my simple .htaccess would be the best performance-wise and compatibility.
Cpanel/WHM • PHP • Perl • Ruby • Full Time Support
LCWSoft - Canada web hosting (based in Newfoundland) since 2007
Servers based in the US and Canada (Uptime Report)
-
04-05-2010, 07:14 PM #34Virtually Flawless ;)
- Join Date
- Apr 2009
- Location
- USA / UK
- Posts
- 4,577
Agreed. If you're using Apache.
and compatibility.
---
Really, this is something that should be configured at the web server daemon level rather than the site level - put that in httpd.conf and turn off .htaccess is you're using Apache and care about performance (although if you're still using Apache you prolly don't care much about performance anyway ).→ RAM Host -- USA Premium & Budget Linux Hosting
█ Featuring Powerful cPanel Shared Hosting
█ & Premium Virtual Dedicated Servers
→ Follow us on Twitter
-
04-05-2010, 08:15 PM #35Newbie
- Join Date
- Nov 2009
- Posts
- 27
With .htaccess is the better, but in the most cases php is more easy for all people, and works in "all" servers (the most servers have php).
-
04-08-2010, 09:47 PM #36Newbie
- Join Date
- Aug 2009
- Posts
- 7
You would want to remove www. perhaps if you were calling that domain via code, keep your domains neat... otherwise for SEO someone above said that was a good reason to remove www., that seems a little silly to me...
-
04-09-2010, 04:49 AM #37Web Hosting Master
- Join Date
- Dec 2007
- Location
- UK
- Posts
- 951
I never use the www prefix on domains, does this matter?
Follow me on Twitter: @conrjac
-
04-11-2010, 07:57 AM #38Newbie
- Join Date
- Apr 2010
- Posts
- 13
It seems to be the easiest way for me instead of making changes to php files.
but am not sure if it's going to make server loads higher because I added some VBSEO codes to my .hatacces file and it is making server loads high because of the rewriting rules , but I removed it along with the VBSEO plugin , I was lucky enough to figure out this before it's too late to remove the plugin
I have been facing lots of troubles with www at the beginning of the domain.
but when I logged in into my forums . The ( www ) disappeared
any ideas ?
Thank you for sharing
-
05-12-2010, 11:02 AM #39Newbie
- Join Date
- Mar 2010
- Posts
- 19
This stuff helps with seo, although i prefer to change domainname.com to www.domainname.com Maybe it is better the other way.
-
05-12-2010, 12:21 PM #40Newbie
- Join Date
- Nov 2009
- Posts
- 27
-
05-13-2010, 04:47 PM #41Web Hosting Guru
- Join Date
- Nov 2005
- Posts
- 282
Its preference whether you want to have your website mainly hosted on www.example.com or just example.com as long as you have valid dns records for both you can redirect one to the other. Or as many different subdomains you want. The only thing is that when people manually enter your web address they are more likely to type www.example.com than just example.com, and it might reduce the load on your server by a few milliseconds if your webserver operated off of www and just forwarded the empty subdomain. Any time you forward with an header it means the remote client will have to send another GET request to the server, which could mean for them (depending on their bandwidth, and line quality) a noticable difference in load times.
And hey look at that this web forum will automatically parse www.example.com into a link while it does not parse example.com into a link. Things like this can make forcing to www more advantagous.
-
06-02-2011, 02:27 PM #42Junior Guru Wannabe
- Join Date
- Apr 2011
- Posts
- 32
Can you extend the script a bit? Like make it query a DB and see where the DB tells www to go to, That would make it easier for creating subdomains.
-
06-02-2011, 11:55 PM #43Newbie
- Join Date
- Nov 2009
- Posts
- 27
This work with www due to the most servers have a type A for www
Code:www A 127.0.0.1
Code:subdomain A 127.0.0.1
-
06-09-2011, 10:34 AM #44New Member
- Join Date
- May 2011
- Posts
- 3
thanks for the informative post
-
06-11-2011, 12:20 PM #45Newbie
- Join Date
- Nov 2010
- Posts
- 21
Or you can put it in your .htaccess file.
-
02-19-2013, 03:47 AM #46Disabled
- Join Date
- Aug 2012
- Posts
- 11
nice to know this php code for this purpose. i only knew .htaccess way.
-
09-20-2014, 02:31 AM #47WHT Addict
- Join Date
- Sep 2007
- Posts
- 120
You can achieved this with the use of Apache's URL rewrite. :-)
EmailHosting.com
http://www.emailhosting.com