I want to show my 404 error page when ever someone gets on a non working / non created page. After a long time of searching on the web I couldnt find any solution so I post one myself. I dont have any .htaccess file either i created it filled it in but in my FTP it kept saying nothing was safed in there and it didnt show any bytes so thats something im also worried of.
So how can i get my .htaccess file to work and show my 404 Error page template? I followed all the steps to make a 404.php file but i dont mind it to be redirected to the same template I made for it but then as a page any of those solutions is fine.
You've got some rewrite rules in your .htaccess file that are preventing a 404 error from every truly happening...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
That basically states that if the requested resource is neither a file nor a directory (basically a 404 error), redirect to /index.php
Try this in your .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# delete the line below to have /index.php/anything trigger a 404
RewriteRule ^index\.php$ - [L]
</IfModule>
# END WordPress
#404 redirect
ErrorDocument 404 /httpdocs/wp-content/themes/avian/404.php
Note
This may make Wordpress quite unhappy however, I'm not sure how it uses internal routing, it may rely on breaking 404s to determine which pages to load by using fake (RESTful) URLs - reinstating 404 errors make cause Wordpress to stop working properly ... I am, however, no expert on it having barely ever touched it.
Related
I have a custom 404 page called 404page.php , and I have the htaccess file with the line that I found should work (this is the only line I have in the .htaccess file)
ErrorDocument 404 /404page.php
It was working fine yesterday, but today I was optimizing images and some other stuff on the website, and when I reuploaded it, the htaccess didn't redirect to 404page.php anymore, but to a page that has this written:
Not Found
The requested URL /asfsdtg was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
(I just typed asfsdtg to test if it was working).
The website is uploaded online and I'm managing it through cpanel (I'm still a beginner). I searched for some solutions, I tried adding another line to .htaccess, then it looked like this:
RewriteEngine on
ErrorDocument 404 /404page.php
I even tried putting the location of the 404page.php as a local link, and the internet link, and it still gave me the weird error page.
Does anyone have some idea whats happening? If you need more info that I didn't supply please tell me what more I can supply
Try out this:
RewriteEngine on
ErrorDocument 404 http://yoursitename.com/404page.php
And be sure that 404page.php exists on the root of your server and is trully called 404page.php not 404Page.php
Be carefull at the characters, this is key sensitive!
Try with like this:
RewriteEngine on
ErrorDocument 404 http://www.sitename.com/404.php
Make to handle any 404 errors.
ErrorDocument 404 /404page.php
If above setting does not works you have to write addition line of code as mentions below.
Which identifies for non existing files and directories and redirect to 404.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ - [R=404,L]
I am new to URL Routing so this issue might be from something which I did wrong. I am using PHP and I need to have simple clean URLs without showing the .php extension in browser. So I used the routing engine from the fat free framework (f3) and added a .htaccess file to the root folder. I followed a tutorial on this and this is the content on my htaccess file.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ framework.php [L,QSA]
So i need to redirect all request to framework.php file if no physical file or directory is matched.
Everything was working fine with this, but I recently tried indexing with google and as it turns out robots get a 403 error when the url of the website is given.
For example www.abc.com works fine on browser but gets a 403 error in fetch as google tool. The error is occurring in google page speed insights as well.
When you try to access it as www.abc.com/benefits/ again it works fine on browser but get a 404 error in fetch as google tool.
My robots.txt file contains the following
User-Agent: *
Disallow:
Allow: /
The error make sense if no URL routing is present because I do not have a index.php file and no physical sub directory called benefits. But since I have the rewrite rule I cant figure out why its giving the 403 and 404 errors and why only for robots.
Could any one tell me what’s I am doing wrong? Thanks
As w3d pointed out the problem is not only for the robots and there was nothing wrong with the htaccess file.
The problem was with my main controller which is framework.php
I renamed that to index.php and now the issue has been solved. For some reason even though the url and folder structure is virtual, the server is looking for a index file in the root folder.
Against my advice, my employer hired someone from fiver.com to create an online 'Task Manager'. They were given access to our database and FTP server. When I returned to work after 5 days, a certain page on our website was no longer working. The page contains a list of all our customers with several SQL filters. If I apply one of these filters through the search.php script, it will return the following error:
Not Acceptable
An appropriate representation of the requested resource /admin.php could not be found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Word Press is the main reason for this error. The 3rd party we hired from fiver.com installed a plug-in using Word Press. The application was, as expected, not up to a decent a standard and has since been removed from our site, but the error 406 still remains.
I have already tried creating a .htaccess page with the following content:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
With this file uploaded onto the server, the error 406 is no longer displayed.
But the browser will automatically redirect to index.php.
I am running out of ideas!
I have a custom CMS. It works very well except for one thing. I am wondering how best to implement 404 functionality. The site should only have the following url types
index.php?upn=something
or
gallery.php?groupId=2
Any directories that are appended to the url after index.php or gallery.php should throw 404's. Also I would like to throw a 404 if the content is not found in the database when a upn is specified. I realise that I can throw the header in php. But I said I would try to get a little more insight into this problem overall. So if ye have any info or pointers I'd appreciate them.
I like to do this programatically from my PHP code. You could write some simple Route Component, that try to find what you want. Today you're routing just to actions (index.php?upn= and gallery.php?groupId=) but someday in the future you may add new one, and you should change your .htaccess, which is more difficult. If you do it all in your app tier you can change it simpler.
Paste this code in a .htaccess file at the root of your project, and will route every request to router.php. Once you have the request you can decide what action to do.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ router.php?url=$1 [QSA,L]
</IfModule>
Hope it helps.
You'd have to return the 404 in the php code, but you can set the 404 handler like so in htaccess:
ErrorDocument 404 /errors/notfound.html
I am trying to rewrite my urls to go from /controller/method to index.php?/controller/method, and that is mostly working, except that forms won't submit correctly. I have some routing set up, but the forms are also breaking on non re-routed urls. Here's a little context.
I have moved my index.php out into a separate web folder that is the web root, so there is no chance of exposing application files. I'm not sure whether this would potentially cause this problem, but it's something slightly unusual about my installation. My directory structure looks like:
+ codeigniter/
+ application/
- models, views, etc
+ system/
+ web/
- .htaccess
- index.php
- css, javascript, images, etc
My .htaccess is pretty simple:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
It seems to work fine on XAMPP for Windows, but it is broken on a basic Ubuntu LAMP stack. When I submit a form, nothing happens. The page that the form directs to loads, but as if the form hadn't been submitted.
Sorry, one more important piece of information: If I leave the index.php in there, so the urls look like /index.php/contacts/edit/1, it works.
Let me know if I can provide any more information. Thanks!
Turns out a part of the .htaccess that I didn't include was causing the error to be difficult to find.
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I had assumed that this would show a CodeIgniter error page if it reached that block, but it turns out (I assume) that CodeIgniter was valiantly trying to salvage the situation by looking at the path in $_SERVER, from which it was able to get the page it was supposed to display. However, since the path didn't exist, none of the $_POST data made it through. In the error log I was seeing this line:
[error] File does not exist: /path/to/web/contacts/edit/1
Enabling mod_rewrite solved the problem.