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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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"); ?> Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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] Quote Link to comment 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" Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
MSUK1 Posted November 4, 2010 Author Share Posted November 4, 2010 thankyou Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.