Home > SEO Tips > 301 redirect with spaces in file names

301 redirect with spaces in file names

Spaces in file names and how to 301 redirect

This was a problem that I came across the other day – the project I am working on had a lot of links pointing to old files that had been renamed and moved on the server. So how do you make use of these links and not have users clicking these links and landing on error pages?

How to use a 301 redirect to make use of broken links

If you are on a apache/linux server you can use the .htaccess file to redirect the broken links to their correct locations, here’s how:

redirect 301 /folder/file.html http://www.example.com/newfolder/newfile.html
redirect 301 /folder/ http://www.example.com/newfolder/

The first line is used in the .htaccess file to redirect a specific file to a new location. Simply type the location of the old file and then the full address (you must include the http://) of where the new file is located. Upload this to the root directory of your server. This will now redirect the old URL to the new URL you want. Put each redirect on a new line in the .htaccess file – you can have as many lines as you need.

The second line in the example will redirect an entire folder to a new folder location, using the same method. Using a 301 redirect is the most search engine optimised way to redirect URL’s like this. Also it can make use of links you weren’t benefitting from before.

How to 301 redirect with %20 spaces

This problem has me frustrated but fortunately there is a simple solution. The site I am working on has some files which have spaces in the file names e.g. file name.html
Here is the 301 redirect solution:

redirect 301 “oldfolder/file name.html” http://www.example.com/newfolder/file%20name.html

Yes simply add quotes to the first part of the redirect! Make sure you use spaces though, and only have the quotes round the first part. The reason I kept the %20 (the HTTP code for a space in the URL) in the redirect part of the file name was because I was not renaming the pages just yet – I wanted to keep the same pages at the same positions in the search engines.

This version is for linux/apache hosting only, if you wish to do a 301 redirect on a windows server use IIS.

Remember when making pages for your website do not use spaces in the filenames!

wayne SEO Tips , ,

  1. Eleonora
    July 26th, 2009 at 16:07 | #1

    Hi,
    I’m working on a website and I need to redirect the url http://www.namesite.com/%20 to http://www.namesite.com, because Google, when crawling the site, saw it as an error.

    I tried your method putting:
    Redirect 301 “/%20″ http://www.namesite.com/
    in the .htacces but it seems to be not working.

    Have you got some other method to suggest?

    Thanks!
    E.

  2. January 18th, 2010 at 19:24 | #2

    Thank you!!! It worked perfect, the quotes were all my server needed to properly redirect the page I had foolishly named using a space.

  1. No trackbacks yet.