How can I redirect directory using htaccess including files with spaces in the names
Posted
by James
on Stack Overflow
See other posts from Stack Overflow
or by James
Published on 2010-04-12T13:16:06Z
Indexed on
2010/04/12
13:22 UTC
Read the original article
Hit count: 251
mod-rewrite
Hi, I am dealing with a situation where someone has handed me a bunch of old files on the server which already have a lot of incoming links directly to them (mostly pdf files). I now have the files organized but in a different directory. Before it was 'domain/manuals/file' now it is 'domain/media/manual/file'. I am trying to resolve this issue using an htaccess file.
Many of the files have spaces in the names (not something I can control) and because they already have links to them I can't just go through renaming them. I have found that I can redirect files individually when they have spaces in the names by using quotes such as:
redirect 301 "/manuals/file 123.pdf" "http://www.domain.com/manuals/file 123.pdf"
However, there are loads of these files and I wondered if there is a way to create a regular expression that will handle spaces in file names that I could use to redirect the entire directory. I should add that some files contain decent file names with no spaces in, some have one space and others more than one space. It's not pretty.
If you've encountered this problem before I would really appreciate hearing your advice, I'm running out of ideas.
Thanks.
© Stack Overflow or respective owner