404 custom error template .htaccess - .htaccess

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 /

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

htaccess Help required redirecting old deleted links

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]

Need to specify full URL in .htaccess?

I have the following line in my .htaccess file and it works.
ErrorDocument 404 http://localhost/error.php?code=404
When I change it to either of these it doesn't work anymore (don't know which is correct):
ErrorDocument 404 error.php?code=404
ErrorDocument 404 /error.php?code=404
The .htaccess file and error.php are in the same directory. Why is this happening?
Note: I'm on Wampserver
FULL .HTACCESS FILE
RewriteEngine on
RewriteRule ^([a-z]+)$ $1.php
ErrorDocument 404 http://localhost/error.php?code=404
The reason this is not working is because of the query string.
When you don't supply a full URL to the ErrorDocument directive, Apache treats is as a local file path relative to DocumentRoot. Slightly confusingly, you do need to use the leading / even though it is technically a relative path.
Now, what you want to do is actually not as simple as it may seem on the face of it. Because you are now dealing with a local path, the query string portion no longer has a special meaning, and will be treated as a literal part of the file name - and obviously the file is not called error.php?code=404, it's just called error.php. Thankfully though, it is possible with a little bit of messing around, because ErrorDocument does generate an internal request which is passed through the standard routing engine. What we will need here is a little bit of mod_rewrite magic.
Try the following:
ErrorDocument 404 /error-404.php
RewriteEngine On
RewriteRule ^/?error-([0-9]+)\.php$ /error.php?code=$1 [L,QSA]
This assumes that your .htaccess and error.php files both reside in the DocumentRoot.
In my opinion, 404 (like 403, 502, ...) code is a HTTP code so it could be logic that the instruction ErrorDocument, which reference to HTTP process in your case, needs a http:// instruction.
Using DaveRandom's solution, I simply added the R flag to RwriteRule and it works.
Try this configuration:
ErrorDocument 404 /error-404.php
RewriteEngine On
RewriteRule ^/?error-([0-9]+)\.php$ /error.php?code=$1 [L,R,QSA]
For me it works on Apache 2.4.12

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!

.htaccess in cakephp

I do not want to use mod_rewrite on cakephp and I want to use cakePHP's pretty URLs. So I have removed all the .htaccess files
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
and uncommentted this line on core.php
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
Noe the problem is...if I am putting controller and action in URL it is showing a 404 not found error.
http://www.mydomain.com/controller/action - showing not found
Can anyone help me out this.
Try either:
http://www.mydomain.com/index.php/controller/action
http://www.mydomain.com/index.php?controller/action

Resources