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]
Related
So I'm new to .htaccess and I can't get it to work properly.
This is my file:
ErrorDocument 404 http://localhost/404.php
It goes to the "404 page". But how can I keep the wrong domain while it still redirects to the page? Ex. if a typed "http://localhost/soup/yummi.php" - It should still display that url?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subfolder/403.php [L]
Solved it for me :)
Try this one out please
ErrorDocument 404 /soup/404.php
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]
I'm facing a quite strange behaviour of my .htaccess. Whenever I try to access a link rewritten by mod_rewrite, my .htaccess is refering to the root and not the subdirectory I'm working in. My folder structure looks like that:
htdocs/
blog6/
.htaccess
My .htaccess looks like that:
Options +FollowSymLinks -MultiViews
ErrorDocument 401 /core/error/401.php
ErrorDocument 403 /core/error/403.php
ErrorDocument 404 /core/error/404.php
ErrorDocument 500 /core/error/500.html
RewriteEngine on
RewriteBase /blog6/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /index.php?page=$1 [L]
But whenever I try to access a file through a rewritten url, I get a 404 error and the log says:
C:/xampp/htdocs/index.php' not found or unable to stat
So it seems like my .htaccess wants to access the file in the htdocs instead of using the subdirectory. When I write /blog6 in my rewriteRule, everything works fine, but why RewriteBase isn't working properly? If it's important, I'm using <base> in my html
RewriteBase works only if you provide relative URL in target of RewriteRule so change your code to:
Options +FollowSymLinks -MultiViews
ErrorDocument 401 /core/error/401.php
ErrorDocument 403 /core/error/403.php
ErrorDocument 404 /core/error/404.php
ErrorDocument 500 /core/error/500.html
RewriteEngine on
RewriteBase /blog6/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L,QSA]
I am trying to figure out how to program a .htaccess file to redirect any file or directory that does not exist to the index.html file in the web root.
I sort of figured it out with this directive:
ErrorDocument 404 /index.html
The problem is that an HTTP 404 error is still returned by the web server. I'd like to show a permanent redirect for all these files instead. It is important that a 404 error NOT be returned.
Suggestions appreciated!
Try adding this rule to your htaccess file instead:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ /index.html [L,R=301]
This checks that the request isn't a file, isn't a directory, and isn't a symlink. Then redirects whatever the request is to /index.html.
There is a convinient FallbackResource directive in Apache
FallbackResource /index.html
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