Custom Search

News World

Oct 8, 2012

Information Technology :: 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 http://www.example.com/newpage.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" "http://www.example.com/new page.html"

No comments:

IT Conversations

Moneycontrol Latest News

Latest new pages on Computer Hope

Latest from Infoworld

Door Lock

Door Lock Import Top Door Lock from China Contact Quality Manufacturers Now