How can i change the 404 Error Page with .htaccess.
Actually, i have an htaccess file that contains rewrite rules.
In brief,i want to customize 401, 402, 403, 404 and 405 error pages.
My reputation does not allow me to comment, so i have to answer.
Example:
Options +FollowSymlinks -MultiViews -Indexes
RewriteEngine On
#
# .htaccess content
#
ErrorDocument 403 403.php
ErrorDocument 404 /AnyDir/404.php
ErrorDocument 500 /OtherDir/500.php
Related
i have site there both url are working as follow
https://domainname/abc
https://domainname//abc
so i just want to redirect //abc to 404 error page for preventing duplicate content i try following rule but didn't work.
RewriteRule ^//(.*)$ 404
ErrorDocument 404 https://domain_name/404
i also try using RedirectMatch as follow
<IfModule mod_alias.c>
RedirectMatch 404 ^//(.*)$ https://domain_name/$1
</IfModule>
I want to set the path of 404 error file inside .htaccess file without typing the domain normaly inside it every time when I change the domain.
For example :
This is normal code ErrorDocument 404 http://www.example.com/404.php
I want to set it to ErrorDocument 404 404.php
I mean widthout domain url .
Is there an variable in .htaccess like $_SERVER['HTTP_HOST'] in php to get domain url ?
Whene I set the 404 code as ErrorDocument 404 404.php its show empty page and inside it text like "404.php" only .
thank you for help ^_^ .
This is what I use in my .htaccess file. Hope it helps.
# This redirects browsers that experience a 404 error (Not Found) (and others listed)
# to the file "error.php" located in the same directory as your .htaccess file.
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
The .htaccess works fine on the live server but here on my development system, it does not appear to be doing so. If I purposely enter an invalid address, it just gives the basic Apache error.
It is enabled in Apache2.conf with AccessFileName .htaccess but is there anything else that needs to be enabled to make it work? At one point it was working but many system updates later, I just noticed that it is not.
RewriteEngine On
AddDefaultCharset UTF-8
Options -Indexes Includes +FollowSymLinks
DirectoryIndex index.php
ErrorDocument 400 /messages/validate.php?error=400
ErrorDocument 401 /messages/validate.php?error=401
ErrorDocument 403 /messages/validate.php?error=403
ErrorDocument 404 /messages/validate.php?error=404
ErrorDocument 406 /messages/validate.php?error=406
ErrorDocument 408 /messages/validate.php?error=408
ErrorDocument 500 /messages/validate.php?error=500
<Files .htaccess,db_mysql.php,config.php,common.php>
Order Allow,Deny
Deny from all
</Files>
I am using the following code in my .htaccess:
ErrorDocument 404 error_page.php?msg=404
When I trigger a 404 error, I get a page that says this:
error_page.php?msg=404
Is there something that I am doing wrong?
Thanks
Not sure if you can pass query strings to the document designated by ErrorDocument, Something you can try is using it in conjunction with mod_rewrite:
ErrorDocument 404 /error-doc-404
ErrorDocument 405 /error-doc-405
ErrorDocument 500 /error-doc-500
RewriteEngine On
RewriteRule ^error-doc-([0-9]{3})$ /error_page.php?msg=$1 [L]
Since this is in a subdirectory off of the document root, it changes everything.
Say the subdirectory is /something/
ErrorDocument 404 /something/error-doc-404
ErrorDocument 405 /something/error-doc-405
ErrorDocument 500 /something/error-doc-500
RewriteEngine On
RewriteRule ^error-doc-([0-9]{3})$ /something/error_page.php?msg=$1 [L]
Assuming that your error_page.php file is actually in the /something/ subdirectory.
i want to redirect to the error page if the page is not found. so i have add this code in .htaccess file.
# '404 Not Found' error
ErrorDocument 404 /index.php?p=error&code=404
but when i test it will not redirect to index.php file.
my whole .htaccess file code is here
#AuthName "Restricted Area"
#AuthType Basic
#AuthGroupFile /dev/null
#require valid-user
#<Files "/site/captcha/">
# Allow from all
#</Files>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
## File paths are relative to the Document Root (/)
# '400 Bad Request' error
ErrorDocument 400 /index.php?p=error&code=400
# '404 Not Found' error
ErrorDocument 404 /index.php?p=error&code=404
# '403 Forbidden' error
ErrorDocument 403 /index.php?p=error&code=403
# '401 Unauthorized' error
ErrorDocument 401 /index.php?p=error&code=401
# '500 Internal Server Error'
ErrorDocument 500 /index.php?p=error&code=500
############################# Pages ##########################################################
RewriteRule ^home/$ index.php [S=1]
RewriteRule ^home$ index.php [S=1]
</IfModule>
To start with -- move all ErrorDocument directives out of <IfModule mod_rewrite.c> -- there is no need at all for that.
Right now it tells Apache: "use ErrorDocument ONLY IF mod_rewrite is enabled".
If it does not work for you right now, then it is extremely likely that mod_rewrite is not actually enabled. But if you place them outside <IfModule mod_rewrite.c> block (just before it), then it should work (as long as .htaccess is recognised and processed by Apache):
#AuthName "Restricted Area"
#AuthType Basic
#AuthGroupFile /dev/null
#require valid-user
#<Files "/site/captcha/">
# Allow from all
#</Files>
Options +FollowSymLinks
# '400 Bad Request' error
ErrorDocument 400 /index.php?p=error&code=400
# '404 Not Found' error
ErrorDocument 404 /index.php?p=error&code=404
# '403 Forbidden' error
ErrorDocument 403 /index.php?p=error&code=403
# '401 Unauthorized' error
ErrorDocument 401 /index.php?p=error&code=401
# '500 Internal Server Error'
ErrorDocument 500 /index.php?p=error&code=500
<IfModule mod_rewrite.c>
RewriteEngine on
# Pages
RewriteRule ^home/?$ index.php [L]
</IfModule>
P.S.
I have also modified your rewrite rules: jointed them together into single rule.