I did it in layout.inc because it was the only file mentionning control-structures.php :) I just had a look to error.php, and cannot find where I need to fix the code. Can you fix it for me ? (I'll learn with your commit)
If you look at the code after the stuff you added, you will see that it is supposed to check for an existing exact filename. Now if you use # in the filename, it is not going to exist :)
Now I moved the if redirection to the error.php handler, where other such stuff is located.
Goba