Why 404 page is not showing using .htaccess? - apache

I am using following .htaccess code to showing error message using 2 php page called 404.php and not-found.php when page is not found in my server. But unfortunately it's not working. It's should be show 404.php or not-found.php page if page is not found.
.htaccess code :
Options -MultiViews
ErrorDocument 404 /not-found.php
ErrorDocument 500 /404.php
RewriteEngine on
RewriteRule ^(?:zones/)?update/(\w+)/?$ update.php?z=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

Related

How to show error message using .htaccess If url is incorrect?

Well, I am using .htaccess rules to edit my website url structure. Now, I have following url :
http://localhost/aponit/dev/zones
This url is for zones.php page to edit a form data. After click on edit link it will go to this link :
http://localhost/aponit/dev/zones/update/55
This link is open on update.php page.
Now, If I remove following part from this url
/55 or date/55
then it's showing me error message with appropriate error page. That fine.
But if I remove update/55 from the url then url is look like that :
http://localhost/aponit/dev/zones/ (note the forward slash at the end)
then it's calling zones.php page and stylesheet is broken
BUT I want to show a error page e.g : not-found.php page. How can I do this using .htaccess ?
My .htaccess rules :
Options -MultiViews
ErrorDocument 404 http://localhost/aponit/dev/not-found.php
ErrorDocument 500 http://localhost/aponit/dev/404.php
RewriteEngine on
RewriteRule ^(?:zones/)?update/(\w+)/?$ update.php?z=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
You can use:
Options -MultiViews
ErrorDocument 404 /aponit/dev/not-found.php
ErrorDocument 500 http://localhost/aponit/dev/404.php
RewriteEngine on
RewriteRule ^zones/$ - [NC,L,R=404]
RewriteRule ^(?:zones/)?update/(\w+)/?$ update.php?z=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

Apache - .htaccess: mod_rewrite and ErrorDocument won't work together

I'm not sure what the mistake is here, but I'm not able to redirect 404 errors to a specific page. This is how the .htaccess looks like:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.+) index.php
ErrorDocument 404 http://www.someurl.com/error404/404.php
The error folder and file exist, and when I do a curl -i http://www.someurl.com/notexistent it returns a correct 404 error code. But no redirection, neither curl, nor in the browser. How is that possible?
Sorry, I'm no expert with these .htaccess configurations, help is appreciated.
EDIT 1:
I tried different url's like:
ErrorDocument 404 http://www.someurl.com/error404/
ErrorDocument 404 /error404/404.php
ErrorDocument 404 /error404/
But withouth success.
EDIT 2:
I forgot to mention: mod_rewrite works as expected. Only the 404 redirects do not work.
With your RewriteRule you rewrite all the pages without real file or folder to index.php no exceptions for 404 errors...
Try with:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php? [L,R=404]

URL Rewriting on Apache server causes 404 error page

A few weeks ago I was trying url rewriting on my shared host. It was working for a while, but nowadays it seems to be broke. I don't know what the problem is and I can't solve it by myself. Hope you could help, guys.
This is the plan. I want to delete the extension in the url (e.g. 'file.html' or 'file.php') to only the filename (e.g. 'file'). My code is the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index/(.*)/$ index.php?page=$1
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
ErrorDocument 404 404.php
ErrorDocument 403 403.php
ErrorDocument 401 401.php
</IfModule>
One extended note: this .htcaccess file is in the directory 'portfolio'. The root has another .htcaccess file which is the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
Maybe it is something obvious, but I couldn't find what the problem is. I did try 'RewriteBase /website/', 'RewriteBase /', 'RewriteCond %{REQUEST_FILENAME} !-f' and 'RewriteCond %{REQUEST_FILENAME} !-d' in the first .htaccess file, but that doesn't work.
You can have these rules in /portfolio/.htaccess
ErrorDocument 404 404.php
ErrorDocument 403 403.php
ErrorDocument 401 401.php
RewriteEngine On
RewriteBase /portfolio/
RewriteRule ^index/(.+?)/$ index.php?page=$1 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/portfolio/$1\.html -f [NC]
RewriteRule ^([^.]+)$ $1.html [L]
RewriteRule ^([^.]+)$ $1.php [L]
Your rules for adding .php or .html need to have a RewriteCond to check whether corresponding files exist in your portfolio directory.

How do I avoid a 500 error with .php hiding using mod_rewrite?

I have got this in my .htaccess file:
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
When I try to access a page or directory that isn't there, I get 'Error 500 - internal server error'. I am using GoDaddy, if it is relevant.

Code Ignighter - 404 showing, but correct response

i'm working on a website at work and recenctly move it via svn to my localserver so i can work from home...
The setup went okay, no majors... but code ignighter sends 404 Not Found on pages along with the correct response...
For example i can load 'localhost/home' and it fires my controller and i get correct view, but CI also send 404 in headers for the page....!!
this also happens on my js files...
I can force it to send "200 OK", but doing this on every page seams silly..
Has anyone come accross this problem before...?
I'm using;
Code Ignighter: 2.1.0
Apache : 2.0.63
PHP: 5.1.6
this is my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css|js)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Give the .htaccess example from the documentation a try:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
The following line could be responsible for your 404 response:
ErrorDocument 404 /index.php