MySQL/Apache: Replace spaces with underscores only in certain URLs
Posted
by
javipas
on Server Fault
See other posts from Server Fault
or by javipas
Published on 2011-01-08T10:37:13Z
Indexed on
2011/01/08
10:55 UTC
Read the original article
Hit count: 247
I'm having a problem with some images I'm using on my WordPress blog. After a migration I renamed every image replacing spaces with underscores, so
HIDDEN_264_4062_FOTO_IDF los MID.jpg
was renamed to
HIDDEN_264_4062_FOTO_IDF_los_MID.jpg
But althought the trick was necessary and worked for most of the posts, some of them try to find the old image, with spaces:
This is not found
http://www.example.com/files/HIDDEN_264_4062_FOTO_IDF%20los%20MID.jpg
and this should be the right URL
http://www.example.com/files/HIDDEN_264_4062_FOTO_IDF_los_MID.jpg
Careful, though, 'cause the "%20" is only shown on the browser: the text on the database shows spaces, not "%20".
I'd like to know if maybe I could make a SQL query in my WordPress MySQL database that replaces spaces in .jpg files with underscores. The path of the images is always the same, so the rule should transform this:
/files/HIDDEN_264_4062_FOTO_IDF los MID.jpg
/files/HIDDEN_264_4062_FOTO_IDF_los_MID.jpg
the "/files/HIDDEN_264_" part is always the same, but the rest varies. Is some way to perform this? Maybe a rewrite rule on Apache (our current webserver)?
© Server Fault or respective owner