Nextcloud version: Nextcloud Hub II (23.0.1 RC3)
Operating system and version: Ubuntu 20.04
Apache or nginx version: Apache 2.4.25
PHP version: 7.4
The issue you are facing:
We have more than 200 sharing links. We had to migrate nextcloud on a different server with different lan IP and hostname and we lost access to the folders through those links.
Any chance to bulk modify the path in links database or fix that issue without renaming links one by one ?
You have a share table. But there is no hostname. If you create a new share, is it working with the new hostname? And then you can check the difference with the old shares in the table.
There’s no way around using the new “hostname”, respective the new (sub.)domain.name if you changed it in your web server and Nextcloud config. The “…/s/m4PGe879bx578y” part of the links should stay the same but your users have to use the new hostname in front of it, like that: https://newhostname/s/m4PGe879bx578yE
But why did you change the domain name in the URL in the first place? Normaly you would just point the DNS records for cloud.domain.tld or cloud.tld to the new IP (A record) or to the hostname of the new server (CNAME) when you migrate web applications like Nextcloud to a new server…
If you’re using the IP address of the server in order to access your Nextcloud there is no way to preserve the links when you migrate Nextcloud to a server with another IP address. The only way would be using a DNS name and then point that name to the IP address of the new server. Obviously such a DNS setup would have to be already in place before the migration.
Host name change … old lshare links are directed to the wrong hostname. Game over. Even with some tricky rewrite direction rules…
It was anyway an interesting question, so I did try some rewrite rules on my test bench… Always end up crashing… Even for old links using sharerenamer app …
Maybe a bit offtopic, but I would always use hostnames for your Nextcloud. It is easier to remember, if you move to a different ip, there is no problem, and you can get ssl certificates.
though of just adding my solution since I got the same “problem”.
changing the domain like that is not smart, yada yada - its a small personal cloud in my case, so yeah.
anyway, for the solution - So first all request that go to my cloud on the old domain are send via a provider 301 to the new cloud link. (via Subdomain setting). I have a nginx reverse proxy at my place running, catching all the request, so old cloud.old_domain.com is still in the server_name block for my new cloud.new_domain.com. Then nginx jumps in and rewrites old domain to new domain like this:
(rproxy.conf on nginx, inside that server 443 bracket)
if ($host = 'cloud.old_domain.com') {
return 301 https://cloud.new_domain.com$request_uri;
}
this way you’ll be at the point where the request_uri (something like /m4PGe879bx578yE) will be the only problem. If they changed (what they did for me), you can go into mariadb and adjust the token in oc_share to the old one.
(in mariadb) (for example)
use nextcloud;
select id,token **(maybe name or something else if needed)** from oc_share;
update oc_share set token='m4PGe879bx578yE' where id=12; **(for example, replace token value and id value with what you need)**
hope somebody that stumbles across this can make use of this.