Alias domain redirection

Discussion in 'Installation/Configuration' started by Shaky, Jul 31, 2025.

  1. Shaky

    Shaky New Member

    I can't get my redirections working.
    Three domains: website.com, website2.com, websitesub1.com and websitesub2.com. All have the www auto subdomain.
    Visitors should finally always be redirected to the domain www.website.com.
    In addition when visiting websitesub1.com or www.websitesub1.com visitors should be redirected into the sub directory /sub1/.
    And when visiting websitesub2.com or www.websitesub2.com visitors should be redirected into the sub directory /sub2/.

    I created the webhost with "SEO Redirect" "* => www.domain.tld".
    website2.com as aliasdomains with no redirects.
    websitesub1.com as aliasdomain with "Redirect Type" "R=301,L (Permanent redirect + last rule)" and "Redirect Path" "/sub1/".
    websitesub2.com as aliasdomain with "Redirect Type" "R=301,L (Permanent redirect + last rule)" and "Redirect Path" "/sub2/".

    The .vhost apache config of this webhost has the SEO redirect of the webhost (website.com) as first redirect. So the other redirects will never kick in. This way the aliasdomain redirects are kind of useless, or did I miss something?
    ISPConfig v3.2.12p1
     
  2. remkoh

    remkoh Well-Known Member HowtoForge Supporter

    Don't use SEO redirect "* => www.domain.tld" but use "domain.tld => www.domain.tld".
    That way the alias domain redirects should work on their own and not being hijacked by your current SEO redirect.
     
    Last edited: Aug 1, 2025
  3. Shaky

    Shaky New Member

    So the way to go ist to set following redirects:
    website.com (webhost) SEO Redirect: "domain.tld => www.domain.tld".
    website2.com (aliasdomain) "Redirect Type": "R=301,L (Permanent redirect + last rule)" and "Redirect Path": "https://www.website.com/"
    websitesub1.com (aliasdomain) "Redirect Type": "R=301,L (Permanent redirect + last rule)" and "Redirect Path": "https://www.website.com/sub1/".
    websitesub2.com (aliasdomain) "Redirect Type": "R=301,L (Permanent redirect + last rule)" and "Redirect Path": "https://www.website.com/sub2/".
    Redirects on all aliasdomains even on those (in this example it is only one, but there could be more) that should not redirect to a subdirectory. And writing the main domain into all redirects.

    This is not elegant. Would it be possible to switch the order of the redirects in the resulting .vhost config file?
    Are there any benefits of doing it as it is now? Currently the webhost "SEO Redirect" overrules/disables all aliasdomain redirects (normal redirects and SEO redirects).
    For my understanding the webhost redirects (all, even the HTTPS redirect) should be placed after all aliasdomain redirects.
     
  4. remkoh

    remkoh Well-Known Member HowtoForge Supporter

    What's not elegant about it? It's just plain logic.
    And keeps a clean overview of what redirects to where.

    Unless you also have subdomains.domain.tld as aliases that need redirecting to www.domain.tld too there is absolutely no reason at all to use "* => www.domain.tld" instead of "domain.tld => www.domain.tld".
    Every other alias domain needs it's own redirect.
    Only when you didn't have the redirects to subfolders you could have used "* => www.domain.tld" to redirect all aliases at once.
    There's no way to alter the order from within ISPC.
     
    Last edited: Aug 1, 2025
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    If you don't like how redirects work, you can write your own redirect rules in a .htaccess file and place that in the web folder of the website.
     
    remkoh likes this.
  6. Shaky

    Shaky New Member

    Don't get me wrong. I really like ISPConfig and appreciate all the work that went into it to get it to that level it is currently at. A great piece of software.

    But the order of the redirects in the vhost config file renders all aliasdomain redirects useless when using "* => www.domain.tld" or at least complicates the aliasdomain redirects. This is absolutelly not elegant nor simple. And yes, I think "* => www.domain.tld" on the webhost is the best and most robust redirect to websites with multiple aliasdomains and only one "canonical" domain. Otherwise this redirect option would not be there at all.
    On my live system, I would have to touch 7 aliasdomains and the webhost just becaus of one new aliasdomain that should redirect to a subdirectory. None of the other aliasdomains has redirects.
    Yes, this can all be handled. I put my redirects in the "Apache Directives" under "Options" in the webhost.

    It just seemd so obvious to me that the current order of the redirects in the vhost config is by far not ideal. Of course it works, but on the other hand it could also be so much easier. Just wanted to know if there is any particular reason for this order.
    If not then it might eventually be considered in a future release.
     
  7. remkoh

    remkoh Well-Known Member HowtoForge Supporter

    If you want to change the order you may have a chance by copying file vhost.conf.master from the /usr/local/ispconfig/server/conf/ folder to the /usr/local/ispconfig/server/conf-custom/ folder and change it to your likings.
    I asume alias domain redirects can be put in front of the main domain's redirect but I haven't looked into that.
    Then you would be able to use "* => www.domain.tld" for all your alias domains not redirecting to a subfolder instead of redirecting each alias domain itself.
    Maybe @till can confirm or deny such posibility exists.
    You can never change the order of alias domain redirects though.
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    The order of redirects is fine as it is for me. We do not plan to change it and this would also break all existing installations as they relie on the current order. One always has to make a decision what comes first, in one case a certtain order is fine, in another case a different order might be better. That's why you can create rewrite rules yourself in .htaccess if you do not like the way we set up the rules in ISPConfig.
     
  9. remkoh

    remkoh Well-Known Member HowtoForge Supporter

    He does have a valid point and breaking things is not true.
    In fact it is somewhat broken now, because currently "* => (www.)domain.tld" as main domain's SEO redirect is acting as catch all before any alias domain redirects get a chance to be applied.
    For all non-"* => ..." SEO redirects the order doesn't matter, so nothing will be broken.
    It would make way more sense to put the main domain's SEO redirect last, as a posible catch all.

    @Shaky I've looked into the earlier mentioned vhost.conf.master file.
    You should be able to change things.
    Look for these 3 parts in the file (taken from the latest ISPC version, starting at line 514) and turn the order around.
    Code:
    <tmpl_if name='seo_redirect_enabled'>
                    RewriteCond %{HTTP_HOST} <tmpl_var name='seo_redirect_operator'>^<tmpl_var name='seo_redirect_origin_domain'>$ [NC]
                    <tmpl_if name='apache_version' op='<' value='2.4' format='version'>
                    RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
                    </tmpl_if>
                    RewriteRule ^(.*)$ http<tmpl_if name='ssl_enabled'>s</tmpl_if>://<tmpl_var name='seo_redirect_target_domain'>$1 [R=301,NE,L]
    </tmpl_if>
    
    Code:
    <tmpl_loop name="alias_seo_redirects">
                    RewriteCond %{HTTP_HOST} <tmpl_var name='alias_seo_redirect_operator'>^<tmpl_var name='alias_seo_redirect_origin_domain'>$ [NC]
                    <tmpl_if name='apache_version' op='<' value='2.4' format='version'>
                    RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
                    </tmpl_if>
                    RewriteRule ^(.*)$ http<tmpl_if name='ssl_enabled'>s</tmpl_if>://<tmpl_var name='alias_seo_redirect_target_domain'>$1 [R=301,NE,L]
    </tmpl_loop>
    
    Code:
    <tmpl_loop name="redirects">
                    RewriteCond %{HTTP_HOST}   <tmpl_var name='rewrite_domain'>$ [NC]
                    <tmpl_if name='apache_version' op='<' value='2.4' format='version'>
                    RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
                    </tmpl_if>
    <tmpl_if name="rewrite_is_url" op="==" value="n">
                    RewriteCond %{REQUEST_URI} !^/webdav/
                    RewriteCond %{REQUEST_URI} !^/php-fcgi/
                    RewriteCond %{REQUEST_URI} !^<tmpl_var name='rewrite_target'>
    </tmpl_if>
    <tmpl_if name='use_proxy_protocol' op='==' value='y'>
    <tmpl_if name='ssl_enabled'>
    <tmpl_if name="rewrite_target_is_ssl" op="==" value="y">
                    SSLProxyEngine On
    </tmpl_if>
    </tmpl_if>
    </tmpl_if>
    
                    RewriteRule   ^/(.*)$ <tmpl_var name='rewrite_target'><tmpl_if name="rewrite_add_path" op="==" value="y">$1</tmpl_if>  <tmpl_var name='rewrite_type'>
    
    </tmpl_loop>
    
     
  10. Shaky

    Shaky New Member

    Thank you both for your replies.

    @remkoh
    Using a custom master template would eventually break some feature introduced in the future. I try to not have to keep track of all updates and to not have to think about side effects when changing settings. In just a few months I will not be able to remember the master template anymore. :)

    @till
    I fully understand that changing the order might break some existing installations. Too bad, at least I think so.
    But now you are aware of this behaviour and maybe there is some way to work around it somehow in the future.
     

Share This Page