How To Create Custom Share Links With NextCloud

I run a NextCloud instance and one of the little paper cuts that bug me is that I can’t create a custom link to a publicly accessible folder.

When a shared folder is created in the NextCloud file manager a random URL is created that has the following form:


This is not easy to remember when I want to give out a link to a file I want to share.

I found an easy way to fix this so that https://example.comm/public will redirect to https://example.comm/index.php/s/catTLcZxBbgSjXA using Apache2’s mod_rewrite.

The example here is for Apache2 but you will be able to do something similar with NGINX.

All you need to do is to open the VirtualHost file for your NextCloud instance and add the following lines:

RewriteEngine on
RewriteRule "^/public$" "" [R]

This will redirect https://example.comm/public -> https://example.comm/index.php/s/catTLcZxBbgSjXA. You need to edit this to fit your requirements.

You need to put this in the correct location in your VirtualHost file. You can see it here in a full VirtualHost file:

DocumentRoot /var/www/nextcloud

<Directory /var/www/nextcloud/>
  Options +FollowSymlinks
  AllowOverride All

 <IfModule mod_dav.c>
  Dav off

 SetEnv HOME /var/www/nextcloud
 SetEnv HTTP_HOME /var/www/nextcloud


 SSLCertificateFile /etc/letsencrypt/live/
 SSLCertificateKeyFile /etc/letsencrypt/live/
 Include /etc/letsencrypt/options-ssl-apache.conf

 CustomLog /var/log/apache2/ common
 ErrorLog /var/log/apache2/

 RewriteEngine on
 RewriteRule "^/public$" "" [R]


After you’ve added those lines restart Apache2:

systemctl restart apache2.service

And test it from an anomalous browser tab.