Problem with custom error pages.
My server root is "C:\www" and error pages are in "C:\www\errors".
So I put a .htaccess file in "C:\www" with following:
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html
ErrorDocument 500 /errors/500.html
This works for anything in "mysite.net". But I also have subdirectories like "first.mysite.net", "second.mysite.net" and so on, and .htaccess from root doest work there. It's searching for "errors" folder in these subfolders and return the default 404 page.
I've tried this:
ErrorDocument 500 C:/www/errors/500.html
ErrorDocument 500 C:\www\errors\500.html
Doesn't work.
ErrorDocument 500 http://mysite.net/errors/500.html
This works, but it makes a redirect and I don't want this. I want the browser to keep adress line the same.
Can anyone make this clear for me? Thanks.
If they are subdomains with seperate virtualhost definitions you need to check virtualhost definitions and AllowOverride settings for those subdomains. See http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride and change AllowOverride setting as needed.
Related
I need to disable Apache 401 error message or bypass it completely , in case of errors only back end application error codes should be displayed.
Thanks
Rakesh
Add following to your .htaccess file (works if AllowOverride allows it).
ErrorDocument 401 /URL/TO/YOUR/BACKEND/RESPONSE
Custom error documents are configured using the ErrorDocument directive, which may be used in global, virtualhost, or directory context.
More info about Apache ErrorDocument
Currently I have a few ErrorDocuments in my .htaccess (which is located in the www/site directory) like ErrorDocument 404 /site/error, which work.
However, there is one directory in this site dir which should not have these custom error documents. So whenever an user tries to access /site/no_custom_errors/non_existing_file.png, I should get the default Apache error page and not my custom error.
How would I achieve this?
Your apache config for that directory can change it, or if "AllowOverride FileInfo" (see: http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride) is active for that site or directory, then an .htaccess file in that directory will work containing:
ErrorDocument 404 /site/otherErrorDoc
see: http://httpd.apache.org/docs/current/mod/core.html#errordocument
Alternatively, it could be done in a <directory> directive in httpd.conf or in a virtual host like so:
<Directory path/to/special/directory>
ErrorDocument 404 /site/otherErrorDoc
</Directory>
see: http://httpd.apache.org/docs/2.2/mod/core.html#directory
I have an Apache web server running on Amazon EC2 and I am trying to make a custom 404 page which I did, but I want it to popup when a mistyped or wrong URL is requested. This is my .htaccess code
ErrorDocument 404 /404.html
I saved my .htaccess file in my /var/www/html directory. Am I doing something wrong? Because when I typed in a wrong url, the default Apache 404 Error keeps popping up and I don't want that to drive visitors away. Is this possible? Thanks!!!
confirm that AllowOverride directive is set to All in your httpd.conf
secondly .htaccess should be kept inside the root directory of your code.
I figured it out. I used the same code:
ErrorDocument 404 /404.htmlBut instead of putting it in my .htaccess file, which never worked, I put the same code in my httpd.conf file which I found under the directory /etc/httpd/conf/httpd.conf Thanks for all your help!
I have the following piece of code in my .htaccess file to force redirecting to custom error pages:
ErrorDocument 404 /ErrorPages/404.php
ErrorDocument 403 /ErrorPages/403.php
ErrorDocument 400 /ErrorPages/generalError.php
ErrorDocument 401 /ErrorPages/generalError.php
ErrorDocument 500 /ErrorPages/generalError.php
Everything works fine on port 80, but when it comes to SSL, the standard error pages are shown.
To be more specific:
http:www.mydomain.com/NoExistingPage.php redirects to the custom error page
https:www.mydomain.com/NoExistingPage.php DOES NOT redirect to the custom error page
am I missing something here?
Thanks in advance
Try putting a duplicate .htaccess file in the /secured folder and see if that works. The vhost for the https daemon is probably using /secured as doc_root which means even if the .htaccess from the regular doc_root is below the secured folder it will be ignored.
I am trying to create a custom 404 error for my website. I am testing this out using XAMPP on Windows.
My directory structure is as follows:
error\404page.html
index.php
.htaccess
The content of my .htaccess file is:
ErrorDocument 404 error\404page.html
This produces the following result:
However this is not working - is it something to do with the way the slashes are or how I should be referencing the error document?
site site documents reside in a in a sub folder of the web root if that makes any difference to how I should reference?
When I change the file to be
ErrorDocument 404 /error/404page.html
I receive the following error message which isn't what is inside the html file I have linked - but it is different to what is listed above:
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 404 /JinPortfolio/error/404page.html
When you corrected it in your second try, the reason you see that page instead is because http://localhost/error/404page.html doesn't exist, hence the bit about there being a 404 error in locating the error handling document.
.htaccess files are disabled by default in Apache these days, due to performance issues. When .htaccess files are enabled, the web server must check for it on every hit in every subdirectory from where it resides.
Just figured it was important to note. If you want to turn on .htaccess files anyway, here's a link that explains it:
http://www.tildemark.com/enable-htaccess-on-apache/
Instead of adding them to your .htaccess file, you can add them to any of your virtual host files.
<VirtualHost *:80>
DocumentRoot /var/www/mywebsite
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorDocument 404 /error-pages/404.html
ErrorDocument 500 /error-pages/500.html
ErrorDocument 503 /error-pages/503.html
ErrorDocument 504 /error-pages/504.html
</VirtualHost>
Where error-pages is a subfolder in the mywebsite folder, containing the custom error pages. Make sure you restart your apache to view your changes.
$sudo /etc/init.d/apache2 reload
Whatever url you enter as the default 404 page must be either absolute or relative from the root folder : That's why some make the mistake of treating its url like the rewrite engines' url which is relative from the folder where .htaccess is located.