how to get current path of .htaccess file - .htaccess

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

Related

Change 404 Error with .htaccess: Custom 404 error page

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

Can I do multiple error handling with single line code on .htaccess?

I am currently working on a project using PHP. I need to know whether I can do multiple error handling with just a line of code. Multiple error means 404 or 403 or 400 or any https-status-error.In general to do this sort of error handling we should write;
ErrorDocument 404 /404.php
ErrorDocument 400 /400.php
ErrorDocument 403 /403.php
But I want to minimize the code and redirect all https-status-error code to a single page.Instead of writing the code below is there any short alternative;
ErrorDocument 404 /error.php
ErrorDocument 400 /error.php
ErrorDocument 403 /error.php
ErrorDocument 401 /error.php

Https 404 Redirection in htaccess

Please tell me how to redirect 404 page of following example
https://www.example.co.in/
Create a php page and call name it 404.php and put your redirect urls.
Open .htaccess file and add the following:
ErrorDocument 404 /404.php
All done.

htaccess file does not take me to 404 error page

I have created a .htaccess file and placed it in my root directory for 404 error page, but when I type a random subdirectory after my URL, it takes me to the index.php file instead of my 404.php file. I have the following code in my .htaccess file.
ErrorDocument 404 /error/404.php
What am I doing wrong?
/error/404.php indicates your file location is /var/www/html/error/404.php
If the name of your project directory is, lets say myweb, then your .htaccess should be
ErrorDocument 404 /myweb/error/404.php

.htaccess redirect error page problems

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.

Resources