1

I currently have a 404.php page from a certain theme I'm using but I would like to override any WP foncutionaly regarding 404 errors.

I would like to set a 404 error handler via my .htaccess but for some reason wordpress is still serving it's 404 page.

# 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]
**ErrorDocument 404 /home/username/public_html/my404page.php?next=**
</IfModule>
# END WordPress
  • Have you tried putting the ErrorDocument 404 /home/... etc line above the wordpress rules (Above #BEGIN Wordpress) – Tobias Beuving Nov 5 '15 at 1:25
  • Anyway, outside of the # BEGIN and # END because wordpress will overwrite everything between these lines. If you want to add stuff to the htaccess file, do it outside of those lines, so before # BEGIN... and after # END WordPress it is safe to write your own stuff. – Tobias Beuving Nov 5 '15 at 1:31
  • Thanks for the comments but nothing happens/changed after I moved the ErrorDocument before or after the Wordpress rules. – mele Nov 5 '15 at 9:40
  • To be sure, I assume you placed the star signs (**) just for pointing out which line you are talking about? – Tobias Beuving Nov 5 '15 at 12:33
  • Sorry, I looked at my own project where I have it working, but noticed I ditched all the wordpress generated htaccess code. IIn my answer I explain why you can't use the errordocument directive. Is there a specific reason why you don't want to use the 404 wp template? – Tobias Beuving Nov 5 '15 at 13:05
1

As far as I can see, it is not possible to use a custom 404 ErrorDocument directive in your htaccess file because WordPress' index.php will always be found when processing the htaccess content. (unless ofcourse index.php got deleted for some reason)

Because index.php is found, it will not trigger the '404 not found' ErrorDocument directive. The ErrorDocument directive will thus be ignored.

That is - if you stick with the htaccess code generated by WordPress (which I strongly recommend).

It is possible to work without the htaccess rules that WordPress generates, but it requires you to write htaccess rules for the processing of permalinks etc yourself.

I did this in a project where I decoupled WordPress almost completely from the frontend, but I can't recommend doing that for ~98% of the use cases. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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