jasonc Posted May 22, 2011 Share Posted May 22, 2011 how do i make it so visitors get rerected from site.com to www.site.com so visitors only use the www.site.com been told that i need to add something to the .htaccess file to make this so. what is this ? Quote Link to comment https://forums.phpfreaks.com/topic/237095-get-users-to-view-the-wwwsitecom-instead-of-sitecom/ Share on other sites More sharing options...
ignace Posted May 22, 2011 Share Posted May 22, 2011 RewriteEngine On RewriteCond %{HTTP_HOST} ="site.com" RewriteRule (.*) http://www.site.com$1 [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/237095-get-users-to-view-the-wwwsitecom-instead-of-sitecom/#findComment-1218630 Share on other sites More sharing options...
jasonc Posted May 22, 2011 Author Share Posted May 22, 2011 hey thank but still i am still taken to the home page being www.site.com if i was to visit say site.com/mypage.html i would like the visitor taken to www.site.com/mypage.html same for site.com/anotherpage.html would take them to www.site.com/anotherpage.html and finally site.com/anotherfolder would take them to www.site/anotherfolder Quote Link to comment https://forums.phpfreaks.com/topic/237095-get-users-to-view-the-wwwsitecom-instead-of-sitecom/#findComment-1218632 Share on other sites More sharing options...
ignace Posted May 22, 2011 Share Posted May 22, 2011 Or if ($_SERVER['HTTP_HOST'] == 'site.com') { header('Location: http://www.site.com' . $_SERVER['REQUEST_URI'], 301); exit(0); } Quote Link to comment https://forums.phpfreaks.com/topic/237095-get-users-to-view-the-wwwsitecom-instead-of-sitecom/#findComment-1218633 Share on other sites More sharing options...
jasonc Posted May 22, 2011 Author Share Posted May 22, 2011 but that would require me to add this to every page ? Quote Link to comment https://forums.phpfreaks.com/topic/237095-get-users-to-view-the-wwwsitecom-instead-of-sitecom/#findComment-1218634 Share on other sites More sharing options...
jasonc Posted May 22, 2011 Author Share Posted May 22, 2011 or can PHP code like this go in the .htaccess file ? Quote Link to comment https://forums.phpfreaks.com/topic/237095-get-users-to-view-the-wwwsitecom-instead-of-sitecom/#findComment-1218635 Share on other sites More sharing options...
ignace Posted May 22, 2011 Share Posted May 22, 2011 No. The PHP example is for if you use the FrontController concept. Quote Link to comment https://forums.phpfreaks.com/topic/237095-get-users-to-view-the-wwwsitecom-instead-of-sitecom/#findComment-1218636 Share on other sites More sharing options...
jasonc Posted May 22, 2011 Author Share Posted May 22, 2011 i tried RewriteEngine On RewriteCond %{HTTP_HOST} ="site.com" RewriteRule (.*) http://www.site.com$1 [R=301,L] but if i was to visit site.com/page.html it takes me to www.site.com and not www.site.com/page.html Quote Link to comment https://forums.phpfreaks.com/topic/237095-get-users-to-view-the-wwwsitecom-instead-of-sitecom/#findComment-1218645 Share on other sites More sharing options...
ignace Posted May 22, 2011 Share Posted May 22, 2011 Maybe? RewriteEngine On RewriteCond %{HTTP_HOST} ="site.com" RewriteRule (.*) http://www.site.com/$1 [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/237095-get-users-to-view-the-wwwsitecom-instead-of-sitecom/#findComment-1218670 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.