IP to domain redirect

Discussion in 'ISPConfig 3 Priority Support' started by zyzzza, Oct 17, 2013.

  1. zyzzza

    zyzzza Member

    Hi,

    Hope someone would know - how is it possible to redirect or "assign default URL for IP address"? I've got one domain on one IP , and for now if you eneter IP - you will see the site with IP address in the address bar . What I need - when the IP is entered in adress bar it would redirect to the domain I have in ISP.

    (I had smth called "default domain for IP" in other CP, but I can see a way of controlling this in ISP)
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    If a ip address is entered in the browser, apache will show the first website in alphabetical order that has this ip address assigned. If you want to see the domain name in the url bar of the browser, then you can e.g. add a .htaccess file in the website with a rewrite rule that redirects requests without a domain name to the domain.
     
  3. zyzzza

    zyzzza Member

    I'm on nginx :) Any solution for that ?
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    It should be possible in a similar way with nginx, the main difference is that the rules have to be inserted in the nginx directives field of the website in ispconfig instead of a .htaccess file. I dont have the nescessary nginx rules at hand, but I've forwarded your question to Falko, he is our nginx guru and will know the exact rules :)
     
  5. zyzzza

    zyzzza Member

    OK, thanks, would be good if this is doable from ISP directly in the "Rewrite Rules" on Redirect tab or in the " Available nginx Directive Snippets:" in the options tab
     
  6. falko

    falko Super Moderator Howtoforge Staff

    The SEO Redirects should work for you - just select * => www.domain.tld.
     
  7. zyzzza

    zyzzza Member

    nope, cannot as having subdomains there as well (or will it not impact ?) (Can't play, should be 100% sure as this is production case)
     
  8. zyzzza

    zyzzza Member

    OK, this worked ! :) Even with other subdomains, and subdomains which are on other IPs ...

    Thanks a lot !
     
  9. zyzzza

    zyzzza Member

    Oops, not really ! forgot about m.domain.com which is an alias for the main domain,and in case of *=>domain.tld wont work :(
     
  10. zyzzza

    zyzzza Member

    Hi Falko,

    Still struglling on how to achieve what i need .

    Basically situation is :
    I've got domain MYDOMAIN.COM
    and Alias created in ISPCONFIG for mobile version M.MYDOMAIN.COM

    (here php decides which version user on and switches the proper template, however the site fiels are the same. )

    It all works good , but if someone enters the IP of site or ANYTHING.MYDOMAIN.COM it would render the main MYDOMAIN.COM with ANYTHING.MYDOMAIN.COM in adressbar (we've got wildcard subdomains enabled, as we need lots of dynamic subdomains). This breaks our cache mechanisms as it relies on address.

    If i set in ISPConfig *=> MYDOMAIN.COM redirect - it redirects ALL of subdomains (including alias'ed
    M.MYDOMAIN.COM ) is there a way i can exlude ALIASed domain redirection but keep all others ?

    Thanks
     
  11. falko

    falko Super Moderator Howtoforge Staff

    In this case you have to create custom rules in the nginx Directives field on the Options tab.
     
  12. zyzzza

    zyzzza Member

    Just in case someone will be looking for the same problem:

    Task:
    Redirect Plain IP and ALL subdomains except M.MYDOMAIN.TLD - to MYDOMAIN.TLD
    when M.MYDOMAIN.TLD is an ALIAS of MYDOMAIN.TLD in ISPCONFIG

    Solution:
    On the "Redirect" tab of domain in the "Rewrite Rules" add:

    Code:
    set $my_var 0;
    
    if ($http_host != "MYDOMAIN.TLD") {
     set $my_var 1;
    }
    if ($http_host = "M.MYDOMAIN.TLD") {
     set $my_var 0;
    }
    
    if ($my_var = 1) {
     rewrite ^ $scheme://MYDOMAIN.TLD$request_uri? permanent;
    }   
    
    Enjoy the magic :)
     

Share This Page