htaccess Help: 301 Redirects for URLs with Spaces

A powerful tool for any web developer, .htaccess files can be used for everything from authenticating users to compressing files. But one of the most common uses of .htaccess files is for redirecting traffic and pagerank from one webpage to another. (See our article, 301 Redirects with .htaccess Files on Linux Apache, for more information.)

.htaccess 301 Redirect Examples

In the most basic case where an old page is redirected to a new page, you would set up the redirect rule as shown in the example below.

⇒ Typical Case

Redirect 301 /oldpage.html

If the old or new page name contains spaces, the redirect example above will not work. Leaving spaces in the url will likely result in a 500 Internal Server Error. And if you encode the url, replacing the spaces with %20, you will find that the redirect rule does not work at all. Fortunately, there is an easy solution.

Use Quotation Marks. If you enclose the url that contains spaces in quotation marks, the htaccess redirect rule will work and you won't get any server errors. See the example below.

⇒ URLs With Spaces

Redirect 301 "/old page.html" " page.html"


And that's it!

Tags: , , , , ,


Trackback URL:

Leave a Reply

Want us to work on your project?

Contact us today for a quote. Click here to submit details regarding your project.

If you are making a general inquiry, send an email to

Go Daddy Deal of the Week: Cheap .COM Domains! Offer expires soon!