Archive for May, 2009

City Public Service server fail

I hate the utility company in san antonio. Not only can they not read a fucking meter correctly,  they cannot administer a webserver to boot. I sent this email tonight detailing an issue their server has had for over a year:

From: Jared Rodriguez <jrod@blacknode.net>
To: feedback@cpsenergy.com
Subject: Concerning cpsenergy.com
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Please have your technical staff configure your server to handle HTTP
host request for cpsenergy.com properly. At present, your server is
responding to requests inappropriately:

~ $ host cpsenergy.com
cpsenergy.com has address 208.188.159.143
cpsenergy.com mail is handled by 10 dmsmail.cpsenergy.com.
cpsenergy.com mail is handled by 5 mail.cpsenergy.com.

~ $ nc 208.188.159.143 80
HEAD / HTTP/1.1
Host: cpsenergy.com

HTTP/1.1 400 Bad Request
Content-Length: 39
Content-Type: text/html
Date: Thu, 21 May 2009 05:11:10 GMT
Connection: close

~ $ nc 208.188.159.143 80
HEAD / HTTP/1.1
Host: www.cpsenergy.com

HTTP/1.1 200 OK
Connection: close
Date: Thu, 21 May 2009 05:11:30 GMT
Server: Microsoft-IIS/6.0
Content-Length: 23019
Content-Type: text/html
Set-Cookie: ASPSESSIONIDAAQCDRCA=GFEKMIDCODDEABMGDIMHBIFI; path=/
Cache-control: private

I know IIS is crap, but you still should be able to configure it to at
least meet rfc standards. There is nothing wrong with the following request:

HEAD / HTTP/1.1
Host: cpsenergy.com

So the 400 error is just plain wrong according to rfc2616:10.4.1, which
states:

"The request could not be understood by the server due to malformed
syntax. The client SHOULD NOT repeat the request without modifications."

The server not handling client "Host:" header strings other than
www.cpsenergy.com is not a breach in HTTP header syntax, its a problem
with your implementation. Also, its really annoying to type
cpsenergy.com and get a 400 when any rational server would spit out a
301/2 to http(s)://www.cpsenergy.com, or a 200 and load some other
content. Its just plain lazy in my opinion.

Jared

Welcome

Redirect index.php to root of current directory

An SEO conscious customer was having duplicate content issues for:

http://domain.com/something/

and

http://domain.com/something/index.php

Simply rewriting index.php to / will not be effective as httpd makes an internal redirect to the DirectoryIndex, causing a redirect loop.

In order to distinguish between the internal redirect and a client request, the %{THE_REQUEST} server variable is used.

When placed in the in the Directory context in the httpd.conf or in the .htaccess file located in the document root or desired origin directory, the following rule will achieve the desired results:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]+\ (.*)/index.php\ HTTP/
RewriteRule .*index.php$ http://%{HTTP_HOST}%1/ [L]

Note, this should be placed before any query_string rewriting you are doing for things like clean urls.

This will work recursively from its origin, so:

http://domain.com/something/index.php

and

http://domain.com/something/else/index.php

will be rewritten to:

http://domain.com/something/

and

http://domain.com/something/else/

Return top