Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

if I just type something to provoke a 404 Error on my Wordpress installation, Wordpress doesn't load its own 404.php file, but the Apache server's own 404 error message gets displayed.

What is wrong with my Wordpress installation? Do I need to edit the Apache server's config file and redirect to the Wordpress 404.php page?

UPDATE:

I have partially managed to get this working, I missed the FileInfo directive in the /etc/apache2/sites-available/default file. Not all stuff get caught gracefully, though.

share|improve this question
    
Most of the time WordPress can do what you ask automatically. What is the address of a working page? And the address you are using that returns the wrong 404? Is this multisite? –  s_ha_dum Mar 26 at 12:47
    
Are you using pretty permalinks? And have you checked that mod_rewrite is enabled & the correct rules are in your .htaccess? –  TheDeadMedic Mar 26 at 12:49
    
My installations is at 192.168.1.8/wordpress/ That's the front page of my site. I submit something like 192.168.1.8/wordpress/asdasdasd and then get redirected to the Apache servers's 404 error message page. –  Jaromír the Greenhorn Mar 26 at 12:49
    
I have the default permalink style selected, eg. 192.168.1.8/wordpress/?p=123 –  Jaromír the Greenhorn Mar 26 at 12:50
    
@TheDeadMedic Where do I check mod_rewrite and .htaccess? –  Jaromír the Greenhorn Mar 26 at 12:52

2 Answers 2

up vote 2 down vote accepted

Things are working the way they are supposed to, and possibly the only way they can work. Let me explain.

Without an Apache module called mod_rewrite (or the equivalent Nginx or IIS component) requests to PHP pages have to go to an actual filesystem file. That is what you see with requests like 192.168.1.8/wordpress/?p=123. The file being accessed is the directory "index" file-- index.php. That request is the equivalent of 192.168.1.8/wordpress/index.php?p=123. What you are doing is requesting some other file/directory with requests like this one-- 192.168.1.8/wordpress/asdasdasd-- and no such file or directory exists in the filesystem.

With mod_rewrite and .htaccess properly configured all requests get sent to index.php. Take a look at the stock WordPress .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

That RewriteRule pushes everything (almost everything) to index.php. That allows WordPress to process any request, even requests for files that don't physically exist on the system.

Without pretty permalinks enabled-- that is, with the "default" permalinks selected-- WordPress will not even try to parse the requests so that is equivalent to not having mod_rewrite or .htaccess at all.

And, if WordPress can't parse the request, WordPress can't load the theme's 404.php. Apache, of course, still knows the request is bad and loads its own 404 message.

So, without mod_rewrite, a proper .htaccess file, and pretty permalinks you get the behavior you describe, which is exactly how things are supposed to work.

share|improve this answer
    
I have enabled mod_rewrite with a2enmode rewrite and created the .htaccess file with the sample content on the Wordpress>Using Permalinks page, but it's still not working out properly. I have noticed that if request server/wordpress/index (no .php) it will redirect to the custom Wordpress 404 page but not if I request something gibberish. –  Jaromír the Greenhorn Mar 26 at 13:32
    
By the way, the .htaccess file is in the /var/www/wordpress/ folder is that correct? –  Jaromír the Greenhorn Mar 26 at 13:40
    
.htaccess should be in the same directory as wp-load.php usually. That looks right. –  s_ha_dum Mar 26 at 13:44
    
Well, I am out of clues, what could be messing up this, I guess having all the files in the subdirectory of /var/wwww/ is not a good idea to host Wordpress. But thanks any way, I will accept your answer as the best, since you have put a lot of effort in this and hope that future users will find it useful in fixing their problem. –  Jaromír the Greenhorn Mar 26 at 13:57
1  
"even requests for files that don't physically exist on the system" - technically, the rules only rewrite in this case, hence the RewriteCond's :) –  TheDeadMedic Mar 26 at 14:00

WordPress will only handle 404's if pretty permalinks are enabled - go to Settings > Permalinks and choose one of the options other than default (or use your own).

share|improve this answer
    
I have checked 3 (Day and name, Numeric and Post name) and this doesn't seem to have an effect, i.e. I still get the Apache 404 error message not the 404.php. I am using the Twenty Thirteen theme, by the way. –  Jaromír the Greenhorn Mar 26 at 13:01
    
Check out @s_ha_dum's answer, it'll explain things much better! –  TheDeadMedic Mar 26 at 13:09
    
Thanks for your comments and answer. –  Jaromír the Greenhorn Mar 26 at 13:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.