MSUK1 Posted November 4, 2010 Share Posted November 4, 2010 maybe a silly question, but when somebody visits my site i.e. domain.com i want it to redirect them to www.domain.com example can be seen @ facebook.com Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/ Share on other sites More sharing options...
plznty Posted November 4, 2010 Share Posted November 4, 2010 This is done using .htaccess which should be located in your root folder. Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130313 Share on other sites More sharing options...
MSUK1 Posted November 4, 2010 Author Share Posted November 4, 2010 okay, any idea what i should add to my .hta i looked into adding a 301 permanent redirect on domain.com to www.domain.com but that doesnt seem like the official method to me, doesnt seem right? and i dont think that will help with seo Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130315 Share on other sites More sharing options...
mikecampbell Posted November 4, 2010 Share Posted November 4, 2010 Using PHP you can do this..... <?php header("Location: http://www.domain.com"); ?> Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130316 Share on other sites More sharing options...
MSUK1 Posted November 4, 2010 Author Share Posted November 4, 2010 then everytime the user loads the page they will keep getting redirected no? Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130319 Share on other sites More sharing options...
mikecampbell Posted November 4, 2010 Share Posted November 4, 2010 Oops, didn't properly read the question. Yeah, it'd be best to use rewrite rules in .htaccess or httpd.conf, something like this: RewriteEngine on RewriteCond %{HTTP_HOST} !^www.domain.com [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*) http://www.domain.com/$1 [R,L] If you went a PHP route you'd need to make the redirect conditional. Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130327 Share on other sites More sharing options...
MSUK1 Posted November 4, 2010 Author Share Posted November 4, 2010 what does the $1 at the end of mydomain.com do? Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130370 Share on other sites More sharing options...
MSUK1 Posted November 4, 2010 Author Share Posted November 4, 2010 also what is all of this thats already in my .htaccess file # -FrontPage- IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti* <Limit GET POST> order deny,allow deny from all allow from all </Limit> <Limit PUT DELETE> order deny,allow deny from all </Limit> AuthName msukgroup.co AuthUserFile /home/msuk/public_html/_vti_pvt/service.pwd AuthGroupFile /home/msuk/public_html/_vti_pvt/service.grp i then edited my ht to this: and it doesnt work :/ # -FrontPage- IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti* <Limit GET POST> order deny,allow deny from all allow from all </Limit> <Limit PUT DELETE> order deny,allow deny from all </Limit> AuthName msukgroup.co AuthUserFile /home/msuk/public_html/_vti_pvt/service.pwd AuthGroupFile /home/msuk/public_html/_vti_pvt/service.grp RewriteEngine on RewriteCond %{HTTP_HOST} !^www.msukgroup.co [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*) http://www.msukgroup.co/$1 [R,L] Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130378 Share on other sites More sharing options...
BlueSkyIS Posted November 4, 2010 Share Posted November 4, 2010 here is how I redirect to www using .htaccess: RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC] RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L] The $1 is the content of the (.*). it says "take everything that follows mydomain.com and paste it onto the end of www.mydomain.com" Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130427 Share on other sites More sharing options...
MSUK1 Posted November 4, 2010 Author Share Posted November 4, 2010 Would this mean that if somebody went to a subdimain sub1.mydomain.com it would redirect to www.sub1.... Cause www before a sub Doestnt work on my server Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130431 Share on other sites More sharing options...
BlueSkyIS Posted November 4, 2010 Share Posted November 4, 2010 no. it would mean that whoever goes to http://mydomain.com goes to http://www.mydomain.com Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130432 Share on other sites More sharing options...
MSUK1 Posted November 4, 2010 Author Share Posted November 4, 2010 thankyou Link to comment https://forums.phpfreaks.com/topic/217757-redirect-to-www/#findComment-1130452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.