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 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. 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> 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 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. 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. 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
Archived
This topic is now archived and is closed to further replies.