Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

.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]
like image 690
ProDraz Avatar asked Feb 12 '13 17:02

ProDraz


1 Answers

Solved by placing full URL for error document.

Example:

#### Rule for Error Page - 404 ####
ErrorDocument 404 http://www.domain.com/404.html
like image 61
ProDraz Avatar answered Sep 22 '22 00:09

ProDraz