Some time ago I changed my 404 error page to the main page of my site. (Silly of me, but I'm new at this and it seemed like a good idea at the time.)
Trouble is, I forget how I accomplished it. I was trying the TextPattern CMS at one time, and I think I did it in the CMS, but I don't remember how.
Nowadays, I'm not using the CMS (but the database is still there), and I've created a more descriptive error page, and I've updated my .htaccess file, but the behaviour doesn't change--still the old error (bad) page comes back. I've tried the following in my .htaccess file, all to no avail
ErrorDocument 404 default
ErrorDocument 404 http:/www.mysite.com/404.shtml
ErrorDocument 404 /404.shtml
Any help would be greatly appreciated. Google Webmaster Tools reports 54 "soft 404" errors, which I gotta fix!
-Thanks
I expect that such soft 404 pages are error pages with the server response code 200 and not 404.
It depends a little on the software you are using on the server. I think that your script 404.shtml returns the wrong response code so far you need to edit that file that it will return the response code 404.
In PHP you can do that with:
header("Not Found", 404, true);
Please note that this line must stand before any output!
Related
I tried searching for the answer to this but no luck. Basically I have an .htaccess file which specifies a script to handle 404s:
ErrorDocument 404 /cgi-bin/handle_errors.cgi?404
I have another script which handles page requests according to the query string via a rewrite rule:
RewriteRule ^/path/handler/(.*)$ /cgi-bin/path_handler?$1 [QSA,L]
such that
insaner.com/path/handler/123
would show the content generated by:
insaner.com/cgi-bin/path_handler?123
if some conditions are met for "123". If they aren't, I would like to issue a "404" status, but have that handled by apache itself (which would in fact be then handled by /cgi-bin/handle_errors.cgi?404). So, is such a thing possible? I know I can just call /cgi-bin/handle_errors.cgi?404 from the script after printing the 404 status, but is there a way to get apache to handle the 404? Ie, such that if I later comment out the line in .htaccess, that apache issues its standard 404 response?
Also, is
print "Status: 404\n\n";
enough for the browser? Or do I need to do:
print "Status: 404 Not Found\n\n";
or something like that?
Found this answer to the second part of my question in the CGI.pm documentation:
Note that the human-readable phrase is also expected to be present to
conform with RFC 2616, section 6.1.
EDIT:
This could be solved by having the path handler script print the Status: code then just printing the results of an LWP::UserAgent request (which might clobber important environment variables and data in the process). So it is doable, but is not an approach I would recommend. It is better to break out the error handler code into a module that the path handler can then call itself to generate the content, avoiding the extra step of involving apache, and allowing you to keep any variables and data (and handling that if need be). As my question originally asked, yes, both approaches would also allow things to continue working even if the line in .htaccess was commented out or removed.
today i encountered a very weird problem on joomla that is file does not exist 500.shtml and 400.shtml. In my every web page no matter what i am trying to open it is showing me the same error over and over again which turned off my website. I also google out for it and found some suggestions that are turn off your sef in config file of joomla or change your htaccess by putting a # in front of option and close the htaccess file but still it does not helped me. Any help would be appreciated the most.
In general the first step when dealing with this sort of error would be to turn on error reporting by putting the following at the beginning of your index.php:
ini_set('display_errors','On');
error_reporting(E_ALL);
Doing so might give you some php-specific error message with which I will find it easier to trouble shoot the problem.
This would Display the real error , I had a same trouble, and I found that a new template/plugin/module were creating the problem .So I uninstalled/disabled it .And it was working again.
Cheeers
I've discovered from Google Webmaster Tools that Google has found a bad link somewhere that is throwing a 403 error on my server.
The url is like this:
http://www.example.com/directory/.php
I don't know how that url has come about and the site is too complicated for me to find out, but I'd like to simply place a 301 redirect to:
http://www.example.com/directory/
I've put the correct rule in .htaccess for the redirect, but it doesn't appear to be triggered. It's almost as if the 403 is being generated before .htaccess is processed. Does anyone know why this might be and how I can successfully get the user redirected to the new page?
Except for the fact that the rule may be indeed incorrect, this could also be because this involves looking for a file with a filename starting with a ..
These files are usually "hidden" from the outside world, so it might be that either your Apache (configuration) or your OS does not allow serving this file.
Without knowing more about the configuration, this cannot be analyzed though. You could test it by creating a file called ".test" and see if that's reachable.
I am using a .htaccess file for a short url system that I made. It is supposed to use a file, sudir.php, to find the url that the "code" that was entered is for. But whenever I goto the page at http://localhost/shorturl/t10m3S which doesn't exist so it is supposed to redirect with sudir.php, but it only takes me to a generic "Not Found" page.
This is what i have in my .htaccess:
ErrorDocument 404 /shorturl/sudir.php
If I change it to my phptesting folder, it shows the index of that folder. If I change it to just the shorturl folder, it still gives me the generic 404 error page. If I remove it completely it shows the default page from Apache. So it basically seems like Apache or .htaccess or something doesn't know that the shorturl folder exists even though I can access it and it works. It seems all I need is for it to acknowledge that the folder is there and actually load the sudir.php file, but I don't know what to do.
Additional Info:
I am using a .htaccess file in a different directory to redirect to YouTube pages like how youtu.be does and it works perfectly fine. I did have the same problem with it though at first, but I just renamed the folder it was in and changed the .htaccess to correspond and it started working. I have tried the same with shorturl, but it did not work.
I'm trying to do some very simple page redirection on a shared server that I have very limited access to (no control panel, no error or server logs etc). I've stripped it right back but for some reason i'm still getting a 500 error even with just the following code in .htaccess:
RewriteEngine on
RewriteRule ^contact /contact.php [NC]
When visiting www.domain.com/contact you get a 500 error. I have sent a message to support but they're not very helpful (i'm trying to get the error logs) and it's around Christmas so they'll probably be very slow. Does anyone have any suggestions as to why this might be failing on a shared server as I can't work out why. I don't think they've blocked htaccess use as I have tried setting 404 redirects and preventing access to certain file types via htaccess and both of these work fine.
Thanks so much,
Dave
You are creating a loop with this, because ^contact also matches contact.php.
Try somethin like this:
^contact$