Change domain URL in shared links

Hi everybody,

is it possible to change the URL for the shared links? I mean, if I shared a file by link it is accessible through www.domain.com/index.php/s/HHGRTESS (p.e.), i’d like to change the domain part for every link to www.domainalternative.com/index.php/s/HHGRTESS

Is it that possible? I’ve been googling for a while but I cannot find any actual way.

Thanks!!!

In your config/config.php you can specify which hostname you prefer to use. For your purpose, the first should be sufficient, but I’m not sure if such auto-generated messages take the address from the other variable.

/**
 * The automatic hostname detection of Nextcloud can fail in certain reverse
 * proxy and CLI/cron situations. This option allows you to manually override
 * the automatic detection; for example ``www.example.com``, or specify the port
 * ``www.example.com:8080``.
 */
'overwritehost' => '',

/**
 * Use this configuration parameter to specify the base URL for any URLs which
 * are generated within Nextcloud using any kind of command line tools (cron or
 * occ). The value should contain the full base URL:
 * ``https://www.example.com/nextcloud``
 *
 * Defaults to ``''`` (empty string)
 */
'overwrite.cli.url' => '',

Hi, thanks, but that not worked for my case.

I have NC running fine on www.domain.com, and I want that domain to be the good one, the thing I want is when NC generates an URL from sharing files (or any sharing method) it does not use the primary domain but another one, like www.domainalternative.com. So, if now I share a link with email user, this user receives an email with the following linked URL:

https://www.domain.com/index.php/s/ENMTIUDNS

What i want is NC to change only the URI part of the URL and set another domain, resulting in:

https://www.domainalternative.com/index.php/s/ENMTIUDNS

I have tried with overwrite.cli.url but the links is distributed with original domain yet-

A bit like this to have a usercontent.domain.com?
https://github.com/nextcloud/server/issues/2523#issuecomment-265085663

Would probably also serve your case to use a different domain for sharing…

I’m not sure if there are some apps for shortened-urls which perhaps could be used as well…

The problem I have is that my users access NC via HAProxy with required Client Certificates authentication; If I share a link the external users should need a certificate to access that link, because the URI is the same for domain name and the traffic passes through the Proxy.

So, I had though the best way is that NC generates the links on other domain, so that I can bypass the traffic for that domain and there’s no need to set TLS authentication for that domain.

That feature on github is similar to this problem, but I don’t know how to bring it up to mine :frowning:

You could open a new topic asking for a sharing domain. One purpose was the a usercontent-domain to include stuff in your website, but also your purpose of using an authentication mechanism on the main domain.

Can’t you specify a filter that doesn’t ask for this authentication when you open
www.example.org/s/...?

I’ll try, it seems the only way to get it… ;D

Thanks a lot!!!

Was there ever any resolution to this issue? I have pretty much the same issue.

I don’t know @brucet , I stopped trying to make it working…

But try to put this option in config.php:

‘overwritehost’ => ‘nextcloud.domain.com’,

the URI is your reverse proxy URL.

Regards,

I am looking at the code now to see what I can do.

I have good news and bad news.

First the good news: I have found the PHP code that creates shared links and modified it to return an external domain name for the shares link if one is configured in config.php. I have checked with a php debugger and it seems to work perfectly. The modified code is in apps/files_sharing/lib/Controller/ShareAPIController.php. I modified the formatShare() function to add this functionality.

Now the bad news: It seems that the Nextcloud javascript code must be ignoring the domain in the url returned by formatShare() and substituting the original domain name in the returned shared URL. I have not gotten to the bottom of this issue.

I have created this enhancement request:

If the use case / solution matches your issue, please give it a thumbs up.

Update:
I have fixed this issue in my Nextcloud version which is based on Nextcloud 21.0.0. It works great!!!
Using this feature, anyone with a local server and an HTTP proxy can share files from the local server using URLs which point to the HTTP proxy.
I have closed the enhancement request listed above in this thread.
I would be happy to offer the changes I made to implement this feature to anyone who is interested in adding this feature to the Nextcloud trunk.

1 Like

That does not work for my use case. It redirects the browser to the specified URL. I do not want redirection to a public IP as it slows down Nextcloud when someone is using it from the local LAN.

@brucet
I would like to see your solution. (Even better would be for it to be incorporated into the regular distribution.)

To clarify my use case:
We generally access Nextcloud in the browser over the local, on premise network (also sometimes through VPN) using the local IP address. But “public” access is though a domain. It seems that the default behavior of NextCloud when creating a public share link, is to use the root domain that is being used for that particular log in. So, if I log in with the local IP address and enable a share for a file, the local IP address is the domain used in the link that is generated. But if I log in via the public domain and create (or even just copy an already existing sharing link), then the link is generated with that public facing domain.
Ideally, there would be a preference for the preferred domain for links like this in the config.php file. That way, when a local network user wants to publicly share a file with a link, they don’t have to log out of the site on the local network and then re login through the public facing domain.

If you have a solution please post it here.