Mongrel, .htaccess, cpanel, rewrite, Mongrel::HttpParserError

I just installed my RoR application on my ISP’s server.

This is a Cpanel environment and it creates a .htaccess file:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^xyz.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.xyz.com$
RewriteRule ^(.*)$ “http://127.0.0.1:12001/$1” [P,L]

in a public_html directory. (I changed my domain name in the text above
to xyz because we are not ready to do a product launch.)

The objective, I guess, of the .htaccess file in public_html is to
rewrite (i.e. redirect) www.xyz.com to 127.0.0.1:12001

When I access my website using
www.xyz.com:12001
everything works fine. All my pictures show up, all links work, there
are no errors in production.log and the only error I see in mongrel.log
is

Rails signals registered. HUP => reload (without restart). It might
not
work well.

But that message only occurs during mongrel startup.

When I attempt to access my website via
www.xyz.com
or
xyz.com
I get a ton of mongrel errors complaining that

HTTP parse error, malformed request (127.0.0.1):
#<Mongrel::HttpParserError: Invalid HTTP format, parsing fails.>

REQUEST DATA: “GET /images/Logo 010 - 200x48 - no
background.png?1289857922 HTTP/1.1\r\nHost:
127.0.0.1:12001\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0;
en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729;
.NET4.0E)\r\nAccept:
image/png,image/;q=0.8,/;q=0.5\r\nAccept-Language:
en-us,en;q=0.5\r\nAccept-Encoding: gzip,deflate\r\nAccept-Charset:
ISO-8859-1,utf-8;q=0.7,
;q=0.7\r\nReferer:

_XYZ_session=BAh7BjoPc2Vzc2lvbl9pZCIlOTZlZTVmMjUxOGE3YmIwMGEzNTQ5M2QzZDYwMDI4NmE%3D–fbeb1fb7b16f82da9485523bb84ad3b60fd8d6dc\r\nMax-Forwards:
10\r\nX-Forwarded-For: 98.245.93.82\r\nX-Forwarded-Host:
www.xyz.com\r\nX-Forwarded-Server: xyz.com\r\n\r\n”


PARAMS: {“REQUEST_PATH”=>“/images/Logo”, “REQUEST_URI”=>“/images/Logo”,
“REQUEST_METHOD”=>“GET”}


I don’t even know where to begin to look to solve this problem so I
would appreciate any pointers.

Am I missing some route.rb statement that needs to handle
127.0.0.1:12001 ?

On Wed, Dec 1, 2010 at 9:01 AM, Ralph S. [email protected]
wrote:

HTTP parse error, malformed request (127.0.0.1):
#<Mongrel::HttpParserError: Invalid HTTP format, parsing fails.>

REQUEST DATA: "GET /images/Logo 010 - 200x48 - no
background.png?1289857922

PARAMS: {“REQUEST_PATH”=>“/images/Logo”, “REQUEST_URI”=>“/images/Logo”,
“REQUEST_METHOD”=>“GET”}

OMG. Do you actually have spaces in your image file names?


Hassan S. ------------------------ [email protected]
twitter: @hassan

OMG. Do you actually have spaces in your image file names?


Hassan S. ------------------------ [email protected]
twitter: @hassan

Yes … why not?

I have not had any troubles with spaces in file names on my Windows
development environment, Linux static web page environment, or Linux RoR
environment.

What’s the issue?

On Wed, Dec 1, 2010 at 9:25 AM, Ralph S. [email protected]
wrote:

I have not had any troubles with spaces in file names on my Windows
development environment, Linux static web page environment, or Linux RoR
environment.

What’s the issue?

You just found it – or at least one – apparently :slight_smile:

Spaces in file or directory names are brittle – some programs will
handle them OK, some won’t. You’re far better off avoiding them.


Hassan S. ------------------------ [email protected]
twitter: @hassan

On Dec 1, 2010, at 12:25 PM, Ralph S. wrote:

Yes … why not?

I have not had any troubles with spaces in file names on my Windows
development environment, Linux static web page environment, or Linux
RoR
environment.

What’s the issue?

A URL must not contain spaces, which is why browsers will silently
fill in %20 to replace them whenever they encounter a badly-coded URL.
Seriously, deep in the bowels of the Internet World Domination
Headquarters, Tim Berners-Lee kills a kitten each time you put spaces
in a URL.

Walter

On Dec 1, 2010, at 12:25 PM, Ralph S. wrote:

RoR
environment.

What’s the issue?

The issue isn’t really the filenames directly, but that URLs cannot
contain spaces. Depending on where the space occurs, it should be
encoded either as %20 (in the path portion) or as + (in the query-
string portion). In my experience, even using + rather than %20 in
path components (such as your filename) will work properly even though
it might not be strictly correct per some RFC.

-Rob

Rob B.
[email protected] http://AgileConsultingLLC.com/
[email protected] http://GaslightSoftware.com/

What’s the issue?

The issue isn’t really the filenames directly, but that URLs cannot
contain spaces.
[snip]

-Rob

Rob and Hassan and all …

I don’t believe it … but you were right.

Replacing the spaces with hyphens every and … everything works.

Wow.

I thought I was chasing a wild good but instead I found the goose that
lays the HTML eggs.

Thanks!!!

Ralph