Saturday, November 13, 2010

client denied by server configuration: .htaccess

I was getting the error "client denied by server configuration: /.htaccess" in one specific location recently and I wasn't sure what was going on. Permissions allowed the .htaccess file to be read, because the directives set in that .htaccess were taking effect. There was also no special reason for anyone to try and navigate directly to this directories .htaccess file.

It turns out, that the problem had to do with mod_autoindex. The directory in question is setup to use mod_autoindex and list a bunch of changelogs in the directory. For whatever reason, mod_autoindex wants to access .htaccess while it's building a list of files and since .htaccess files are disallowed for all in the normal Apache configuration, it's getting that permission error.

I've found that adding .htaccess to the IndexIgnore directive will stop this error from happening. Since I also have mod_autoindex ignore the link to a parent directory, my IndexIgnore directive looks like this.

IndexIgnore .. .htaccess

Sunday, November 7, 2010

Select Odd Rows in MySQL

Any time you can use a bitwise operator in place of a function call, it's a good thing. Selecting odd rows from a table in MySQL that have an auto_increment primary key is no exception.

SELECT * FROM mytable WHERE id & 1;

If you're unfamiliar with a bitwise AND, basically what it says is return true of the left operand has the same bits set as the right operand. The number 1 only has one bit set, and conveniently enough that one bit is the same bit that will only be present in odd numbers.

Wednesday, November 3, 2010

Blogger Double Post Bug

Decided to witch back to the default Blogger templates today. I'd stripped out all of the inline management tools when I created the old layout because I never needed them back then. I just started to miss them too much these days though, they make a lot of things easier.

In any event, I'd been putting this off for awhile because when I went to use the blogger template designer, I was getting a double post bug where my posts would show on the page twice whether I was on the index or just a single post page.

I couldn't seem to find an easy way to remove the extra posts widget so I just said screw it. Today though I got tired of putting it off, and decided to dig into the HTML of the template and hunt down the obviously present second posts widget.

From the looks of things, it just wasn't recognizing my posts template when it reverted to the default templates. It was looking at my posts widget as if it were a HTML widget or something other than posts, so it was adding a new posts widget. Though, the editor for my widget was still that of a posts widget, so there was no remove this widget button.

So, I singled out my own posts widget, the one with an id of "blog2", and removed the entire widget wrapper and all of the includables. Worked like a charm.