Forum Topic: Redirecting pages with spaces in the old url (%20)

Forum: .htaccess Forum : Redirecting • Posted by Ann Lockquell • Updated:

Hi,

Just bought you book… happy to have it now… it will be very helpfull…

I?ve search in it the responce of one of my problem and and don’t found it…

I had a new client that have, in his old site, many files to redirect.

Everything goes well untill I have old files that have spaces (%20) in the document?s name…

I have more than 100 like this…

ex:

Redirect 301 /folder/the%20document%20name.pdf http://www.website.com/folder/subfolder/the-new-document-name.pdf

I’ve tried this code

Redirect 301 "/folder/the document name.pdf" http://www.website.com/folder/subfolder/the-new-document-name.pdf

It works but… as soon as I have more than 2 like this in the htaccess file… it bugs

Can you help me?

Thanks

/Ann

6 Replies to “Redirecting pages with spaces in the old url (%20)”

Posted by Jeff Starr

Hi Ann,

Thank you for buying my book, I’ll gladly try to help with this. Using RedirectMatch should help get us there. Here is one way to match the blank space character:

RedirectMatch 301 /folder/the(\s)document(\s)name.pdf http://www.website.com/folder/subfolder/the-new-document-name.pdf

Basically the trick is to use \s for matching blank spaces.

Depending on the URLs, there may be further ways of consolidating the redirect patterns into fewer rules — it all depends on what needs matched.

Posted by Ann Lockquell

Hi again… I’m working with french speaking website also…

I have the same probleme with some url contening accent (ex: e, a, i etc)

How can I code the redirect of those ones?

/Ann

Posted by Jeff Starr

I’m able to redirect URLs containing those containers just using them literally, like so:

RedirectMatch 301 test http:/example.com/

If that’s not working, something else could be interfering.. what are a couple of example URLs that aren’t redirecting properly?

Posted by Ann Lockquell

Ok, I will try it … I will let you know if it works well

Thanks

Posted by Ann Lockquell

Ok… just had the chance to try your trick for the first part of my problem ( blank spaces) I’v try it with only two link to redirect as I’ve done previously with the " " coding…

does not work… it brings me on an error page…

Posted by Jeff Starr

Okay, three questions that will help troubleshoot:

  • What version of Apache
  • What is the URL that doesn’t redirect
  • What is the exact redirect code you are using

It may be that something else is interfering with the redirect, so this info will help diagnose further..