Cory94bailly Posted August 22, 2009 Share Posted August 22, 2009 Hey guys.. I want to redirect http://mysite.com TO http://forum.mysite.com But since the folder 'forum' and 'blog' are in my www root folder, I don't want them to be affected.. Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/ Share on other sites More sharing options...
trq Posted August 22, 2009 Share Posted August 22, 2009 We have an mod_rewrite board here that would have been a more suitable place to post. Anyway, something like this within your doc root should do it. RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com [NC] RewriteRule ^(.*)$ http://forum.mysite.com/$1 [R=301,L] Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-903785 Share on other sites More sharing options...
Cory94bailly Posted August 22, 2009 Author Share Posted August 22, 2009 We have an mod_rewrite board here that would have been a more suitable place to post. Anyway, something like this within your doc root should do it. RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com [NC] RewriteRule ^(.*)$ http://forum.mysite.com/$1 [R=301,L] Sorry about that, didn't see it Now would that redirect something like 'http://mysite.com/sjidsdijg' to 'http://forum.mysite.com/sjidsdijg'? Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-903786 Share on other sites More sharing options...
trq Posted August 22, 2009 Share Posted August 22, 2009 Yep. Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-903787 Share on other sites More sharing options...
Cory94bailly Posted August 22, 2009 Author Share Posted August 22, 2009 Yep. Thanks alot! Sorry for one last thing.. I want it so if they go straight to http://mysite.com, redirect them to http://blog.mysite.com.. If they go to ANYTHING other than just http://mysite.com, redirect them to http://forum.mysite.com.. Examples: http://mysite.com - http://blog.mysite.com http://mysite.com/4946 - http://forum.mysite.com/4946 http://blog.mysite.com/index.php - NO CHANGE I hope that's possible Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-903791 Share on other sites More sharing options...
corbin Posted August 22, 2009 Share Posted August 22, 2009 You should be able to quickly figure out how to do this your self x.x. Anyway: RewriteRule ^$ http://blog.blah.com/ [R=301,L] RewriteRule (.*) http://forum.blah.com/$1 [QSA,R=301] Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-903805 Share on other sites More sharing options...
trq Posted August 22, 2009 Share Posted August 22, 2009 You probably should learn to ask your question properly the first time too. Saves people wasting there time posting incorrect solutions. Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-903807 Share on other sites More sharing options...
Cory94bailly Posted August 22, 2009 Author Share Posted August 22, 2009 I tried learning .htaccess for the past week now and it's just confusing to me.. I'm sorry for not learning.. You should be able to quickly figure out how to do this your self x.x. Anyway: RewriteRule ^$ http://blog.blah.com/ [R=301,L] RewriteRule (.*) http://forum.blah.com/$1 [QSA,R=301] That brings me to http://forum.mysite.com/_forum/_forum/_forum/_forum/_forum/_forum/_forum/_forum/_forum/_forum/_forum/ And same for blog.. It seems to be redirecting even when already in the subdomain.. Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-904076 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 It would sound then like it's going into an infinite loop because your forum subdomain is being affected by the same htaccess file. (The blog one is probably also loop infinitely but it's probably not as apparent since it will still work correctly.) So basically you can either stop the RewriteRule from affecting the forum/blog folders by over riding it, or you can put a condition in there. (The condition is borrowed from thorpe) RewriteCond %{HTTP_HOST} ^(www\.)?blah\.com [NC] RewriteRule ^$ http://blog.blah.com/ [R=301,L] RewriteRule (.*) http://forum.blah.com/$1 [QSA,R=301] Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-904269 Share on other sites More sharing options...
Cory94bailly Posted August 23, 2009 Author Share Posted August 23, 2009 It would sound then like it's going into an infinite loop because your forum subdomain is being affected by the same htaccess file. (The blog one is probably also loop infinitely but it's probably not as apparent since it will still work correctly.) So basically you can either stop the RewriteRule from affecting the forum/blog folders by over riding it, or you can put a condition in there. (The condition is borrowed from thorpe) RewriteCond %{HTTP_HOST} ^(www\.)?blah\.com [NC] RewriteRule ^$ http://blog.blah.com/ [R=301,L] RewriteRule (.*) http://forum.blah.com/$1 [QSA,R=301] I'm sorry but it still does the same thing.. Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-904665 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 Oh, you might actually need the Cond twice: RewriteCond %{HTTP_HOST} ^(www\.)?blah\.com [NC] RewriteRule ^$ http://blog.blah.com/ [R=301,L] RewriteCond %{HTTP_HOST} ^(www\.)?blah\.com [NC] RewriteRule (.*) http://forum.blah.com/$1 [QSA,R=301] Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-904667 Share on other sites More sharing options...
Cory94bailly Posted August 23, 2009 Author Share Posted August 23, 2009 Oh, you might actually need the Cond twice: RewriteCond %{HTTP_HOST} ^(www\.)?blah\.com [NC] RewriteRule ^$ http://blog.blah.com/ [R=301,L] RewriteCond %{HTTP_HOST} ^(www\.)?blah\.com [NC] RewriteRule (.*) http://forum.blah.com/$1 [QSA,R=301] Thank you so much, that works perfectly I'm sorry for any trouble.. /solved Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-904671 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 Quote Link to comment https://forums.phpfreaks.com/topic/171378-solved-htaccess-redirect-help/#findComment-904682 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.