Skip to content
Grav 2.0 is officially stable. Read the announcement →
General

Rename page folder without breaking http links

Started by Laurent C 5 years ago · 2 replies · 421 views
5 years ago

Sometimes I need to rename the folder name to match changes made to the page title. But when I do it if we have already shared the page to social network for example, the feature image is broken.

Detailled example

I have the page https://www.koweb.fr/outils-libres in the folder /user/pages/05.outils-libres. I want to rename to https://www.koweb.fr/outils-libres-pour-collaborer. So, I rename the folder and I create a redirection in site.yaml :

YAML
redirects:
    /outils-libres(.*): '/outils-libres-pour-collaborer$1'

But the page published two months ago on social netword, newsletter, ... and the feature image was https://www.koweb.fr/user/pages/05.outils-libres/01.outils-libres-kit-formations.jpg. The link is now broken.

So I have created a workaround. I copy images of a folder renamed to user/images/archives and I have added redirection in .htaccess file:

TXT
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/pages/.+/(.+\.(jpg|png|jpeg|gif)) /user/images/archives/$1 [L,R=301]

But you may have a better solution ?

Another way is to duplicate the page, unpublish the old one and edit the new one. But in the admin interface the old one is always shown. How can I remove page without deleting files and folder ?

5 years ago

At least for FB you can invalidate shared content with FB debugger and Image should get the correct URL then. Maybe some other services also have something similar. Not sure what's the best way for newsletter - probably a redirect 🤔

5 years ago

But social network aren't the only system using the feature image and it's impossible to remember all shares. And it's complicated to manage redirection. All editors are not developpers.

The best solution would be a deletion of the page from the admin UI without removing files.

Suggested topics

Topic Participants Replies Views Activity
General · by Hanns Mattes, 19 hours ago
1 24 11 hours ago
General · by Andy Miller, 11 hours ago
0 24 11 hours ago
General · by Jerry Hunt, 5 days ago
2 145 2 days ago
General · by pamtbaau, 2 days ago
1 96 2 days ago
General · by Andy Miller, 2 days ago
0 80 2 days ago