Change domain in sharing URLs

Is there a way to change the domain used in file sharing URLs?

The domain I use to access Nextcloud is pretty long, so I set up a shorter one that redirects to it. When sharing via link, I can copy and paste the generated URL into a text editor and replace the long domain with the short one, but it’d be a lot more convenient if the generated URL did that.

I tried setting “overwritehost” in the config, but that broke Nextcloud when I accessed it from a different domain.

The last time this was asked, OP found a different solution, so it was never really “answered”.

@Bugsbane If I add a reply to my own post, will it show up in the new/recent threads again? I feel like after a week, it’s not going to pop up for anyone anymore…

I think it should. That said, when you’re talking about URL rewrites it can get complicated as it dependsa lot on the setup of your particular server, so to be honest, it’s a bit ofa tricky question to answer. You can try bumping it (posting to your own thread, to raise it again). Just be aware that it’s considered bad netiquette to bump more than once a week, or to do it repeatedly.

1 Like

Don’t mind me, just a humble user still seeking a solution…

Basically shared URLs are not bounded to Domain. You need to added Domain as trusted host in config.php:

'trusted_domains' =>
  array (
    'oldLongDomainName.example.org',
    'new.short.org',
  ),

Read more about: https://docs.nextcloud.com/server/15/admin_manual/configuration_server/config_sample_php_parameters.html#default-parameters

and configure your Webserver with e.g. a new VirtualHost with other domain for Apache2.

Pattern is: https://oldLongDomainName.example.org/index.php/s/fDC581z1r46fxaf, where

  • https://oldLongDomainName.example.org/ is totally webserver controlled and independent of NC installation.
  • .../index.php/s/fDC581z1r46fxaf or could be .../nextcloud/index.php/s/fDC581z1r46fxaf is what is shared URL and bounded to NC Application, fDC581z1r46fxafis shared secret URL. This part will remain the same even if you change domain or use 2 different domains, or something else.
1 Like

Thank you for the reply! Adding my regular domains to the trusted_domains list and setting overwritehost to my short domain has almost solved my problem. Everything seems to be working, with the notable (and intended) difference that generated sharing links now use my short domain, despite the page being accessed by my longer domain.

However, when I view the javascript console in my browser’s page inspector, I see 12+ errors that resolving a URL failed because of too many HTTP redirects, listing the URL for the main page on my longer domain. It seems like there’s some script redirecting some request to the short domain and getting caught in an infinite loop that browsers (hopefully) eventually kill. Everything seems to work despite this, but I wonder if there’s any fix for that.

1 Like

Glad to hear that it works fro you!

I think this is already your web server setup “issue” (I would say feature). For web server (e.g. Apache2) you have at least 2 VirtuaHost - one for each domain and if you set Apache2 settings correct cookies will not be shared between domains - for web server those are 2 independent projects/Appalications. Just test it:

  1. login to NC via Domain1
  2. Open NC via Domain2 --> you will be prompted to login page

Basically if you will login in both domains and repeat you test you should not see any errors in console… But I’m not sure :smiley:

NC is only accessed through the longer domain; the shorter domain is completely web-server-controlled, and just redirects to the longer domain with the same path and arguments.

Because the shorter domain doesn’t change the request uri, any redirects from the longer domain to the shorter one would cause an infinite redirect loop (“longer.example.com/test” -> “s.example.com/test” -> “longer.example.com/test” -> … etc).

You’re right that using multiple domains causes its own issues (I had to modify the content-security-policy header, for example), but I think the issue in this case is a redirect loop.