My website was created using underscores in page URLs:
mysite.com/this_is_my_page
But I’ve decided to rename my pages. I’d like to make a universal redirect that replaces underscores with hyphens:
mysite.com/this-is-my-page
I tried doing this using placeholders:
:word1 _ :word2: _ :word3 _ :word4
Redirects to:
:word1 - :word2: - :word3 - :word4
But that doesn’t seem to work.
Is it possible to create a universal redirect that replaces ALL underscores with dashes?
Thanks!
Scott
July 16, 2020, 2:55pm
2
Hey Caspian,
Placeholders will replace anything between slashes, rather than between any characters, for example:
/test/:path/index.html /test2/:path/index.html 301
You may be able to create a bash script that runs through all of your files and dynamically creates this but our otherwise pretty rich redirects feature isn’t going to be able to help
1 Like
I should have thought of this! Thanks!
This took about 30 seconds in bash.
For future people who may be reading this, here’s the script:
for f in *\ *; do echo "$f"; echo "${f//_/-}"; done
Pipe the output into a txt file, then clean it up with a text editor. (I used a vim macro to add quotes to the beginning and end of each line, etc.)
2 Likes