Redirect example.tld/foo/bar to domain.tld/foo/bar

Discussion in 'General' started by trondhuso, Aug 31, 2023.

Tags:
  1. trondhuso

    trondhuso Member

    Hi,

    I am able to do redirect from https://example.tld to https://domain.tld
    but when I try:
    https://example.tld/foo/bar I get a your connection is not secure error (tried to set up letsencrypt, but that didn't work either)
    Then the redirect does not work. it stops there.
    I was expecting: https://example.tld/foo/bar to go to /https://domain.tld/foo/bar
    Same goes with https://example.tld/?action=foo -> not redirecting to https://domain.tld/?action=foo
    I checked the vhost file for the domain, and to me it seems as it should work:
    RewriteRule: ^/(.*)$ https://domain.tld/$1 [R=301,L]

    As you may understand, I am working on moving my site from one domain to another.
    I also tried to set up the old domain as an alias, that also didn't work :/ Nor was the old domain possible to integrate into the new domain certificate (with letsencrypt)
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    1) Add the new domain as alias domain.
    2) Then go to the redirect tab of the website and choose to redirect * to the new domain.
    3) The old (now alias) domain gets added to Let's encrypt automatically. But it must point to the server in DNS already, as Let#s encrypt will not issue a cert for it otherwise.
     
  3. trondhuso

    trondhuso Member

    Ok. So if I am testing this with a minor change in my local hosts file, lets encrypt will not do this. Perhaps changing the hosts file on the server during testing would help?
     
  4. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    /etc/hosts file contents do not affect Let's Encrypt.
     
    trondhuso likes this.
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    You must change DNS. Let's Encrypt will not issue a cert for a domain that is not pointing to the server that requests the SSL cert. See Let's Encrypt error FAQ https://forum.howtoforge.com/threads/lets-encrypt-error-faq.74179/ point 6:

     
    trondhuso likes this.
  6. trondhuso

    trondhuso Member

    Lets encrypt and hosts-file. Thanks for letting me know.
    Since the old domain is still running, I decided to test with some others that would not affect the old main domain.
    Now it does redirect.

    but

    When I do domain.com/foo/bar - it does not redirect
    Why? Shall I do something with the seo redirect also?
     
  7. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    What happens instead?
     
  8. trondhuso

    trondhuso Member

    Hi Taleman (and till - thanks for all the help),
    I am checking with my domain provider to find out if it is my setup that is wrong. I did a test on ping, and www. works nicely, but without www it does not answer.
     
  9. trondhuso

    trondhuso Member

    As they said nothing was wrong, let me copy from the settings:
    domain: myaliasexample.com
    Parent website: example.com
    Redirect type: R=301,L
    Redirect path: https://example.com
    Auto-Subdomain (was set to www. - I have changed it to *.)
    SEO redirect: no redirect
    Active is checked, Don't add is not checked.

    ---
    Edit:
    I have now tested after changing Auto-Subdomain and things seem to work)
    Edit 2:
    Does this mean:
    If I want to have total control over sub-domain redirect, I will have to set up multiple aliases?
    For instance:
    If the site has api.example.com and webhook.example.com, then I will create aliases for those (which makes sense as those will be separate sites)
    And in order to have this control for www.example.com, should I create an alias www.myaliasexample.com and for example.com I should create the alias myaliasexample.com?
     

Share This Page