Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess Redirect on a url with spaces in it

I have a link from anther website that I do not have control of http://example.com/one two three.exe

The correct URL is http://example.com/one_two_three.exe

Note the underscores instead of spaces.

I searched the internet and found this code snippet for .htaccess

# Redirect old file path to new file path
Redirect /one%20two%20three.exe http://example.com/one_two_three.exe

I added this snippet to my preexisting root .htaccess at the top of the file.
But it does not seem to work. My browser does not redirect and I get a 404 error page.

I believe that it has something to do with the spaces in the original URL but I don't know how to handle spaces in the URL.

Suggestions?

like image 469
Steven Smethurst Avatar asked Aug 18 '10 17:08

Steven Smethurst


People also ask

What is a 301 .htaccess redirect?

A 301 Permanent Redirect permanently redirects one URL to another. You set up a 301 redirect using . htaccess to send visitors to a new URL and tell search engines that a page has moved so that the new page can be properly indexed. Some common uses of a 301 redirect with .


1 Answers

You could try a couple of things (both untested)

Redirect "/one two three.exe" http://example.com/one_two_three.exe

or use RewriteRule instead of Redirect:

RewriteRule /one\ two\ three.exe http://example.com/one_two_three.exe
like image 170
KM. Avatar answered Dec 04 '22 19:12

KM.