watsmyname Posted August 30, 2010 Share Posted August 30, 2010 Well i have tried searching my problem but couldnt find, so i m posting it. I want to redirect non existing subdomain to the root domain. But if the subdomain exist then it goes to subdomain. like the subdomain http://mysub.mysite.com doesnot exist so if user enters this url in the browser i want to redirect them to http://www.mysite.com via htaccess. How can i achieve this?? Thanks Watsmyname Quote Link to comment https://forums.phpfreaks.com/topic/212062-redirecting-non-existing-subdomains-to-root-domains/ Share on other sites More sharing options...
watsmyname Posted August 30, 2010 Author Share Posted August 30, 2010 Well i have tried searching my problem but couldnt find, so i m posting it. I want to redirect non existing subdomain to the root domain. But if the subdomain exist then it goes to subdomain. like the subdomain http://mysub.mysite.com doesnot exist so if user enters this url in the browser i want to redirect them to http://www.mysite.com via htaccess. How can i achieve this?? Thanks Watsmyname Currently non existing domain gets redirected to defaultwebpage.cgi. Quote Link to comment https://forums.phpfreaks.com/topic/212062-redirecting-non-existing-subdomains-to-root-domains/#findComment-1105162 Share on other sites More sharing options...
cags Posted August 30, 2010 Share Posted August 30, 2010 If you only have a finite number of subdomains you could do this using mod_rewrite. <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} !^(www|mysub)\.mysite\.com RewriteRule .* http://www.mysite.com%{REQUEST_URI} [R=301] </IfModule> Quote Link to comment https://forums.phpfreaks.com/topic/212062-redirecting-non-existing-subdomains-to-root-domains/#findComment-1105201 Share on other sites More sharing options...
watsmyname Posted September 2, 2010 Author Share Posted September 2, 2010 If you only have a finite number of subdomains you could do this using mod_rewrite. <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} !^(www|mysub)\.mysite\.com RewriteRule .* http://www.mysite.com%{REQUEST_URI} [R=301] </IfModule> Thanks a lot, but this doesnot work. Everytime i type http://mysub.mysite.com the page is redirected to http://mysub.mysite.com /cgi-sys/defaultwebpage.cgi I dont know how to prevent to redirect to defaultwebpage.cgi. Couln't trace out it the code to redirect in httpd.conf file as well. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/212062-redirecting-non-existing-subdomains-to-root-domains/#findComment-1106346 Share on other sites More sharing options...
watsmyname Posted September 2, 2010 Author Share Posted September 2, 2010 well thanks cags. It worked after i added wildcard dns. in httpd.conf file. Quote Link to comment https://forums.phpfreaks.com/topic/212062-redirecting-non-existing-subdomains-to-root-domains/#findComment-1106354 Share on other sites More sharing options...
cags Posted September 2, 2010 Share Posted September 2, 2010 I guess I really should have mentioned that huh? Oh well, least it's working for you now. Quote Link to comment https://forums.phpfreaks.com/topic/212062-redirecting-non-existing-subdomains-to-root-domains/#findComment-1106590 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.