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!
Related
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
So I recently tried to make my own 404 page. It looks good, but after hours of searching how to add it (didn't work), I give up... How can I get the same ErrorDocument on every subdomain with this structure?
/var/www
-main site
-.htaccess
-subdomain
-.htaccess
-error
-error***.html (*** = which error, 404 etc)
...
I tried inheriting .htaccess in /var/www, but it gives me a error:
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
How can i do this? Every try either just gave me "/error/404.html" as html or encountered an error. The document root is in the Subdomains folder, that's the problem. And going back a directory in .htaccess doesn't work (../error).
Well, it seems like it doesn't work. I've now just linked a error.php in every directory and there the htaccess links to them
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
I have a site (e.g. mysite.com) and old versions of the site under a directory are still appearing in search engines (e.g. mysite.com/oldsecton/something.html). There are too many of these links to remove from search engine finds.
I want everything in the /oldsection to redirect back to mysite.com/index.html
i.e. everything in the /oldsection should go to index.html located one directory path back
I have tried different variations of .htaccess inside /oldsection such as
ErrorDocument 404 ../index.html
ErrorDocument 404 mysite.com/index.html
etc...
None of them seem to be successfull.
This should be a simple task but I keep getting an Internal Server Error or a ErrorDocument error.
Inside /oldsection/.htaccess have this code:
RewriteEngine On
RewriteRule ^ /index.html [L,R=302]
Ok, I have a problem, my .htaccess code is:
RewriteEngine on
ErrorDocument 404 /notfound.html
and I have not found.html near .htaccess.
Why is it not working? I don't believe what I'm seeing. I took the tutorial from here
http://www.htaccessbasics.com/404-custom-error-page/
I just want that every time I access www.site.com/ajfasoijfiajsfijaofij to show what is it in notfound.html.
when using ErrorDocument , the file you're specifying is relative to DOCUMENT ROOT not .htaccess location!
Edit:
assume you have notfound.html and you want to use it for folder dir01, you create an htaccess file inside this folder and add this:
ErrorDocument 404 /dir01/notfound.html
If you want to access your file(notfound.html) in browser it would be http://www.example.com/dir01/notfound.html. that's all I could explain!
You can use in your .htaccess file the following code:
RewriteBase /