I know how to create a custom error page using the apache htaccess file:
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
But is it possible to have a custom error page without using the htaccess file?
I have access to the server and all its settings
You can use the same code inside your apache virtualhost ; it will have the same behaviour.
Related
Why is it possible to go further into my index.php file as it was a folder like: www.domain.com/index.php/put_anything_here_and_it_loads_the_file_without_styling
I want it to use the .htaccess to redirect them to the index.php when they go to a file that does not exist like index.php/anything_here - but for some reason it thinks that index.php/anything_here exists...
Right now i have just set my .htaccess to redirect to this page if one of the errors happen:
This is my .htaccess:
ErrorDocument 404 /404error.php
ErrorDocument 400 /404error.php
ErrorDocument 401 /404error.php
ErrorDocument 403 /404error.php
ErrorDocument 500 /404error.php
Thanks
I have created an .htaccess file in my web-based application where i have written the ErrorDocument redirection code lyk below
ErrorDocument 403 /errornopage.html
But it's not working. My Apache version is - 2.2.17 and PHP version is- 5.3.5. But when i try to redirect to a .php page or a .html page whenever 404 error is encountered itz working lyk below-
ErrorDocument 404 /errornopage.php
or
ErrorDocument 404 /errornopage.html
For 403 error code,whether you try to redirect to a .html page or .php page, both are not working. Please Help.
there is difference between 403 and 404
Use This code In htaccess file for 403 :
Options -Indexes
ErrorDocument 403 http://localhost/ht/403.html
You can change the (http://localhost/ht/403.html) to whatever
For 404 error
Options -Indexes
ErrorDocument 404 http://localhost/ht/404.html
So while editing my .HTACCESS file I added the proper lines to redirect users that encounter errors like 404 and 500. It works like a charm if I tell it to display a specific message. However if I tell the file to redirect users to a custom error page it fails.
When testing out my 404 redirect I get this:
Not Found
The requested URL /143/test.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80
As you can see it is stating that my ErrorDocument is not found BUT if I type my ErrorDocument URL in I can go to it myself.
My .HTACCESS file looks like this:
ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
ErrorDocument 502 /error.php
ErrorDocument 504 /error.php
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
# enable PHP error logging
php_flag log_errors on
php_value error_log PHP_errors.log
NOTE: I am using localhost (WAMP).
Thanks.
You were looking for a file called "/143/test.php", but (usually) yout .htaccess goes in the web root. .htaccess is looking for error.php in the /143 directory, so put a copy of it there or use an absolute URL in your .htaccess
When i change the code and add something new it doesnt even lets me load my normal page. If delete the ErrorDocument 404/error.php(and the others) I can normally enter my site.
Here is my sites domain: carnageband.tk
Here is the code:
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
What should i do to bypass the page which it redirects me? LINK
I just had the same problem and the issue seemed to be coming from the .htacess file. The webpage would load okay again after I deleted the .htaccess file.
I was able to fix it by editing the .htaccess file from the cPanel, File Manager instead of transferring the file over FTP, but I'm not really sure why it wasn't working before.
My code looks similar to yours:
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
ErrorDocument 403 /errors.php?p=403
ErrorDocument 404 /errors.php?p=404
ErrorDocument 500 /errors.php?p=500
Am trying to make a custom 404 page for my website and am having .htaccess file in the root directory where am using this rule
ErrorDocument 404 404.php //I want to redirect to 404
So when I change a valid file name like home.php to home1.php it doesn't redirect me instead it echo's 404.php on that page
Side Note: 404.php is in the root directory only
This should do it
RewriteEngine on
ErrorDocument 404 http://www.yoursite.com/404.php
In your .htaccess file, you should be able to use:
RewriteEngine on
ErrorDocument 404 /404.php
You can set additional error documents using this method, but I'd put them in a separate errors directory:
ErrorDocument 400 /errors/400.php
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 500 /errors/500.php
you could do the following to 404 old pages with your htaccess
RewriteEngine on
ErrorDocument 404 /404.php
but i would personally recommend
RewriteEngine on
RewriteRule home.php /home1.php [R=301,L]
as this would do a 301 redirect from the old page name to the new page name, so any cached search engine results would still end up at the correct page instead of hitting a 404
In my case, using an Ubuntu distribution, the directive ErrorDocument has no effect if it is in the .htaccess in htdocs directory or elsewhere: it turned out that it should be put in the proper /etc/apache/sites-enabled/*.conf file, inside the <VirtualServer> directive (for example, if the website is providing https pages, inside the directive <VirtualHost *:443>).