Roots Discourse

Why would my permalinks need a reset every time I deploy?


I there, I’m using a custom script to deploy my bedrock site from Gitlab CI/CD workers.

Basically, I’m running composer install on Gitlab, then I rsync web/ , vendor/ and config/ to my server.
When I do that, I rename the current production folder to something else (eg. /var/www/production --> /var/www/old) and I rsync the new files in the /var/www/production.

My last step is to copy former updates/ files from /var/www/old into the production folder.

When I do that, everything works except one thing : my permalinks stop working. I always need to reset them (by visiting wp-admin/options-permalink.php and saving).

Any idea about why it does that? Is there some cache mecanism behind that? How can I fix this behavior during my deploy?


It sounds like your .htaccess file is not persistent between deployments.

Make sure you save a backup and restore it post deployment.


Thanks @danielroe , as I haven’t been playing with Wordpress in a long time, I thought this file was already provided with core files, whereas it is instead generated (probably depending on the server, nginx, apache) when permalinks are first saved.

Should I add my local .htaccess to my repository, or instead, persist the server’s .htaccess during deployments?


I would persist the server’s .htaccess.

If it’s helpful, solutions like Deployer and Capistrano use a shared folder and symlink files within it to each release’s folder (i.e. releases/{release_number}/web/.htaccess is a symlink to shared/.htaccess).