How can i make it so that my htacces rules return a 404 when invalid urls are entered into the adress bar.
I use the virtualbox for one project and i try create one file .htaccess and i put one error 404 to protect my pages, but when i create my error 404 and sending to the server and refresh my page i have one error 500 on my server.
My code is this:
#my error 404
ErrorDocument 404/file/404.php
Anyone can help me?
I don't know why this happens and I have searched on google.
Greets
You have to wrap your path with quote to determine if it was string
ErrorDocument "404/file/404.php"
A Little White Space causes the issue
Change this
ErrorDocument 404/file/404.php
to
ErrorDocument 404 /file/404.php
Read more here
Related
I'm using below code in .htaccess for showing custom 403 error page on my website.
ErrorDocument 403 /403.php
Though I'm using ErrorDocument 404 /404.php for showing 404 page, and that's working correctly, But custom 403 is not working. It shows me this (See the image http://i.stack.imgur.com/4eTOM.png ) upon opening a restricted directory.
The server is running LiteSpeed. Can anyone help me out?
The sintaxis is good, try:
Make sure you're really having a 403 error with a var_dump(http_response_code());
remove this line from .htaccess, if you got the same result it's possible that the error is in other script file.
change the name of 403.php, if you got the same result it's possible that you have another "ErrorDocument 403" in the .htaccess.
change the name of 403.php and the "ErrorDocument 403" line too, if you got the same result it's possible that the error is in the 403.php script, you can't empty and put only a "test message" and try again now.
How to redirect wrong urls to 404 page?
For example, subdomain.domain.com is fine, but if users enter subdomain.domain.com/asadasd/ada or anything like that, index page is still shown. How to make these mistyped urls show 404 page?
Im using php, mysql, cpanel ect ect.
Yes, I am already using htaccess with ErrorDocument 404 /error.php but no luck here.
you can use '.htaccess'
put this line in .htaccess ErrorDocument 404 /error.php and create error.php file in your root folder.
You will handle the redirection with .htaccess errordocument 404 /404.php
Please follow the complete process in this link
It will help you a lot.
error redirection link tutorials
I am a novice in PHP, I hope you can help me with this problem.
How can I create a custom 404 error page in PHP without going anywhere or redirect it to other page.
Ex. mysite.com/no-where
The page no-where does not exists. I want to display a 404 error message with design on that URL.
How can I get the current URL? I got an error on this. Coz I want to check the header if its 404.
$url = $_SERVER['REQUEST_URI'];
$array = get_headers($url);
$string = $array[0];
if(strpos($string,"200")) {
echo 'url exists';
} else {
echo 'url does not exist';
}
Create a .htaccess file and put the following line in it:
ErrorDocument 404 /errorpageFileName.php
That will set the page 'errorpageFileName.php to your error 404 page. You can of course change the file name to your likings.
You can read more in-depth about it here:
Custom 404 error issues with Apache
It's really important to have a correct 404 error page, because:
It helps your site / webapp visitors to guide for the correct place in your site
Much better SEO
It's just looks better
In additional the the answers here, I would suggest you to have different messages for different error types. For example, define in your .htacess file an error page for different failure types:
ErrorDocument 500 /500.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
More information about custom 404 error pages.
If you are using apache as a web server you can create a file named .htaccess in the root directory of your website. This can contain various rules, including error handling, as follows:
ErrorDocument 404 (Your site error 404 page URL)
For example:
ErrorDocument 404 http://example.domain/custom-404-page.html
add this line in .htaccess
ErrorDocument 404 "Page not found."
Use a 404 header and then require your 404 template / page.
header('HTTP/1.0 404 Not Found');
include '404.php';
exit;
That or you can configure Apache to serve up a custom page.
If you are using apache as a web server and cpanel, just click menu error page, choose 404 error not found and edit the editor with your custom html page and save. You will get automatic file 404.shtml in your folder.
If you are using vps openlitespeed and webadmin panel, there is error not found and fill with your custom 404 html page.
If your panel is cyberpanel at openlitespeed, just create your custom 404 html page (ex:404.html), then edit your vHost Conf and fill with line:
errorpage 404 {
url /404.html
}
And save it
In codeigniter how do I redirect to a custom HTML page when 500 error occurs?
I have tried following code in .htaccess but it does not work:
ErrorDocument 500 /errors/error_500.html
error_500.html is my custom HTML page and its location is application/errors
The ErrorDocument directive, when supplied a local URL path, expects the path to be fully qualified from the DocumentRoot. In your case, this means that the actual path to the ErrorDocument is
ErrorDocument 500 /path/errors/error_500.html
try
ErrorDocument 500 http://localhost/errors/error_500.html
When you corrected it in your second try, the reason you see that page instead is because http://localhost/errors/error_500.html doesn't exist, hence the bit about there being a 500 error in locating the error handling document.
In Codeigniter actually it has a custom 500 error page.
So if you find your getting a generic 500 error page means, that it could be Apache overriding the codeiginter 500 error page.
You could also try to override it in the .htaccess to direct it to your own custom 500.html,
but then you will miss out any of the error information provided by codeiginter:
ErrorDocument 500 /errors/error_500.html
You could also edit the codeiginter 500 error page found in /application/errors/. I think it is the error_php.php file.
i'm having this issue with my server, i'm trying to do a Error 404 display, but whn i go to an invalid URL i get this message.. Please where could the problem coming from?
The requested URL /church/ffff.php was not found on this server.
Additionallt, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request
thank you.
oh it's because the htaccess doesnt automaticly enabled on local host you need to do this:
click on wamp icon
apache->apache modules-> and enable rewrite_module
Whats your .htaccess look like?
You can add a custom handler like this:
In .htaccess (the top of it is best)
ErrorDocument 404 404.php
it seems like the server dont have accses to the 404 file, to fix this you should put the file in the same folder as your htaccess and instead of writing a full path(/c:wamp/www/church/404.php) you should just write the file's name - 404.php