a custom 404 page for all my subdomains. - .htaccess

I want all my subdomains to have the same custom 404 error page. In the htaccess file of the htdocs folder I have tried the following solutions:
ErrorDocument 404 /www/errordocument/404.php
ErrorDocument 404 www/errordocument/404.php
ErrorDocument 404 http://www.mydomain.com/errordocument/404.php
None of them seems to work except for the last one. Only this one gives a 302 redirect and changes the url in the address bar. Which I don't want. I can make a 404 file + htaccess file in all the subdomains only than if someone goes to a non existing subdomain they dont get the custom 404.
how can this be done?
note: server has Apache 2.0 handler

You can keep /errordocument/ folder directly under DocumentRoot of parent domain and then have this directive in the .htaccess of parent domain:
ErrorDocument 404 /errordocument/404.php
After this under all the sub domain's DocumentRoot folder (which will be a sub directory under parent's DocumentRoot) create symbolic links like this:
cd sub1; ln -s ../errordocument; cd -
cd sub2; ln -s ../errordocument; cd -

Related

404 routing issue - AWS Linux / Wordpress site

We are running a WordPress site on a AWS EC2 Linux instance and have created custom 403 and 404 error files (both html files). The files are located in the root of the website.
The root .htaccess file has been amended to include the following section:
# Custom Documents
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
The site uses a theme and within this there is a 404.php file. The problem is that any 404 requests are being routed to this file instead of the 404.html file.
The httpd.conf file has all access set for the root folder var/www/html so there’s nothing in it that I can see that would be blocking the .htaccess file. As a double check I added some 301 redirects into the .htaccess file just to check if they were getting hit and they were working.
Also checked if there were any other .htaccess files which might be overriding the one in , there were some in a plugin but from what I can see they shouldn’t have any impact.
Is there anything else which could be overriding the .htaccess file?
ErrorDocument 404 doesn't work in Wordpress like regular pages. Wordpress by default shows 404.php content from inside your selected theme. You can put your custom code in that 404.php file.
Here is official Wordpress guide for Creating an Error 404 Page

Redirect everything to 404 except files in public folder

How redirect everything inside rootfolder to 404, except files in root/public folder? Directory listing must be disabled everywhere and .htaccessredirected to 404 as well. It's possible to make that with one .htaccess file?
Currently i have Redirect 404 / in root, but when trying to access .htaccess, it's forbidden. Thanks
To redirect everything inside rootfolder to 404, except files in root/public folder ,you can use the following Rule in your /root/.htaccess .
RewriteEngine on
RewriteRule !public - [R=404,L]
and to disable directory listing for all folder/subfolders, add this line to your /root/.htaccess
Options -Indexes

.htaccess redirect subdomain 404 to main domain 404

I'm working with a site that used to use a subdomain to link to an externally hosted blog. This has since been deleted and incorporated into the main site. The subdomain now just houses a .htaccess file with 301 redirects for the blog articles.
I also have a 404 page set up for any other remaining links to the subdomain. The problem is that I want the 404 to be served from the main domain, not the subdomain. Instead of blog.example.com/404, I want to serve www.example.com/404.
Not sure if it matters, but on the server, my subdomain is a folder inside of the main domain:
html/ = www.example.com
html/blog/ = blog.example.com
Remove any 404 ErrorDocument line from DOCUMENT_ROOT/blog/.htaccess
In your DOCUMENT_ROOT/.htaccess add this line:
ErrorDocument 404 /blog/404.html

Use 404 ErrorDocument that is in a sub directory

I have a htaccess file in a sub folder like so:
/subfolder/.htaccess
In the htaccess file the following code to set a 404 ErrorDocument
ErrorDocument 404 /404.php
The issue is the 404 page in the root directory is loaded rather than the one in the /subfolder/ folder. I can't simply change the htaccess file to use /subfolder/404.php because the system is going to be installed in lots of different places.
Is there a way to reference the files in the directory that the htaccess is in?
I just had the same problem and found you page...If you have domain/folder and want to redirect anything from the folder back to the domain's index, use ErrorDocument 404 /
...I'm not sure if this goes to the root folder or one folder up, but in your case (and mine) they are one in the same.
Hope this helps!

404 errors being redirected to the homepage instead of custom 404 page

I have a site hosted on an Apache server. I have created some custom error pages and the following text at the top of my .htaccess file:
ErrorDocument 404 404.html
ErrorDocument 500 500.html
ErrorDocument 401 401.html
I have also tried,
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
ErrorDocument 401 /401.html
Both the htaccess file and the custom pages are in the root directory of the server.
The problem is that when I enter a garbage url (where I would expect to see my custom 404 page) I'm simply being redirected to my index page.
Try if your server is properly set up to parse and process .htaccess files in the first place (i.e., check if AllowOverride + AccessFileName directives are correct). For example, write some stuff in that you know will work and look if it actually gets executed (like a ridiculous rewrite rule). Also, look up your httpd log files for errors.
If it does get executed properly, the problem might be that your server is setup not to allow all kinds of overrides with .htaccess files. Your syntax however, is basically correct.

Resources