1

I have access to an Ubuntu Machine with apache installed, which I connect to Using PuTTy.

For some reason my .htaccess file is not working, this is all it contains:

ErrorDocument 404 /handler.php

Instead of going to the handler.php page it prints out the general Not Found apache page.

I've searched Google and all I can find is information saying make sure in your apache config AccessFileName is set to .htaccess and AllowOverride is set to All.

I made the'e changes to my config file (/etc/apache2/apache2.conf) and it now contains this:

AccessFileName .htaccess

<Directory />
    AllowOverride All
    #AllowOverride None
</Directory>

I restarted apache (sudo /etc/init.d/apache2 restart), but I am still getting the exact same problem.

Sorry, I'm rather unfamiliar with Linux and Apache Config.

Bart De Vos
  • 17,911
  • 6
  • 63
  • 82
user491704
  • 187
  • 2
  • 7
  • 3
    does handler.php exist? Are you sure? – gd1 May 23 '11 at 13:13
  • Which browser have you tested with? – kapa May 23 '11 at 13:16
  • Definitely yes, and it's in the same directory as the .htaccess file –  May 23 '11 at 13:18
  • Make sure the permissions on the .htaccess are accessible to the Apache user. Have you tried using handler.html? – Abe Petrillo May 23 '11 at 13:18
  • Is that the top level directory? What happens when you go to www.yoursite.com/handler.php? –  May 23 '11 at 13:19
  • @bazmegakapa Tested with Chrome and IE 8 –  May 23 '11 at 13:19
  • @Dan yeh, when I go to www.site.com/handler.php it displays the file as expected. –  May 23 '11 at 13:21
  • @Abe Petrillo - I will try renaming as .html an let you know, can you explain more what you mean about the permissions being accessible –  May 23 '11 at 13:22
  • I would like to see the resulting error page. Can you point us to the actual website or a pastebin containing the output HTML code? – gd1 May 23 '11 at 13:29
  • You should also try `ErrorDocument 404 "This is a 404 Error Message, dammit"`. If it does not work, the problem should be on the Apache side. – kapa May 23 '11 at 13:31
  • @bazmegakapa changed it like you suggested, still the same error. –  May 23 '11 at 13:35
  • @gd1 - try www.friendtrend.net/nopage (the page doesn't exists). I have change the .htaccess now to show a string instead as bazmedakapa suggested, before the handler.php just contained a basic: Hi –  May 23 '11 at 13:37
  • Are you sure mod_rewrite is enabled? http://www.tutorio.com/tutorial/enable-mod-rewrite-on-apache –  May 23 '11 at 13:52
  • @Zyava I think `ErrorDocument` does not need `mod_rewrite`, it is a [core service](http://httpd.apache.org/docs/2.0/mod/core.html#errordocument). – kapa May 23 '11 at 14:10
  • Can you try to write something else in the .htaccess like "deny from all" just to see if it gets parsed? – gd1 May 23 '11 at 14:40
  • 2
    grep -R AllowOverride /etc/apache2 : try to see if any active configuration file (in conf.d or sites-enabled) is not putting some restrictions on a parent directory of your webroot (for / it's ok, but if someone can put a restriction on /var/www/mysite). You can check the .htaccess is read by setting deny from all inside (you should get access denied) – regilero May 23 '11 at 15:15
  • @regilero, thankyou very much. I used the grep command as you said, it turns out AllowOverride was set to none inside /etc/apache2/sites-available/default - If you wish to add as an answer I will accept. Thanks to all others for your insight – user491704 May 26 '11 at 21:47
  • @user491704 : answer done – regilero May 27 '11 at 07:24

2 Answers2

2

grep -R AllowOverride /etc/apache2 : try to see if any active configuration file (in conf.d or sites-enabled) is not putting some restrictions on a parent directory of your webroot (for / it's ok, but if someone can put a restriction on /var/www/mysite). You can check the .htaccess is read by setting deny from all inside (you should get access denied)

regilero
  • 1,480
  • 1
  • 9
  • 14
0

Apache is not able to locate your handler.php file.

This file should reside in the DocumentRoot folder itself, of the VirtualHost (website).

Definitely yes, and it's in the same directory as the .htaccess file

This could be your problem. The path in that Directive is always relative to the DocumentRoot folder, not to the location of the .htaccess file.

Check URL http://www.example.com/handler.php as this is the URL you are telling Apache to redirect to.

http://httpd.apache.org/docs/2.2/mod/core.html#errordocument

rightstuff
  • 630
  • 1
  • 5
  • 6
  • This doesn't seem to me, because Apache would output the error page which tells "Error 404, additionaly an error 404 was encountered while trying to load the error page" or something like this. And he already checked for handler existence, you are some hours in the past. Hence -1 – gd1 May 23 '11 at 15:07
  • Place this file in the DocumentRoot folder or modify to... ErrorDocument 404 /url-path/to/htaccess/file/folder/handler.php – rightstuff May 23 '11 at 15:09
  • rightstuff most likely the .htaccess doesn't even get parsed, because otherwise apache, if it couldn't find the error handler, would have shown the other (modified) error page. – gd1 May 23 '11 at 15:39
  • gd1 I understand what you are saying, but trusting that the user is making a distinction between the standard 404 and server modified 404 error message is unwise. – rightstuff May 23 '11 at 16:08
  • The OP said the offending page is www.friendtrend.net/nopage This is a standard error hence the .htaccess is not parsed. – gd1 May 23 '11 at 22:10