ProDraz
ProDraz

Reputation: 1281

Redirect to a php/html file on 404 error with .htaccess

I want to redirect all 404 errors to "404.php" for example.

I've tryed using ErrorDocument 404 /404.php in .htaccess, but without luck, perhaps my other rules are not allowing this somehow, I'm not really sure as I couldn't find this info on www.

If anyone have idea how to solve this, please shout :P

My current .htaccess

#### pie thingy ####
AddType text/x-component .htc

#### Rule for Error Page - 404 ####
ErrorDocument 404 /404.html

#### url rewriting ####
Options +FollowSymlinks
RewriteEngine on

#### REDIRECT IF NO SUB-DOMAIN ####
RewriteCond %{HTTP_HOST} ^([^.]+)\.([^.]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1.%2/$1 [R=301,L]

#### Remove "www." from any subdomain requests ####
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.precisehire\.com [NC]
RewriteRule (.*) http://%1.precisehire.com/$1 [R=301,L]

#### Rules for rewriting from PHP to HTML with fallback ####
RewriteCond %{REQUEST_URI} ^/(.*)\.html$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)\.html$ $1.php [nc]

Upvotes: 6

Views: 14372

Answers (2)

Siraj Alam
Siraj Alam

Reputation: 10085

It's not necessary to give the full URL. You can also mention the absolute path like

ErrorCodument 404 /pages/error.php

which is a better way of doing this than the accepted answer.

Upvotes: 0

ProDraz
ProDraz

Reputation: 1281

Solved by placing full URL for error document.

Example:

#### Rule for Error Page - 404 ####
ErrorDocument 404 http://www.domain.com/404.html

Upvotes: 12

Related Questions