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
Related
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 using laravel 5.0 on my server. i've just uploaded some images to my public/uploads folder.
But when i try to access them eg. /uploads/image.jpg, i'm receiving a 404 Not Found error.
Additionally my firefox browser says "Page is not redirecting properly" when i try to access just the "/upload/" folder(where i think it should be saying 403 forbidden or something).
how can i solve this problem? heres my .htaccess file :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I think the problem for "The page isn't redirecting properly" is the follwoing line in your code:
RewriteRule ^(.*)/$ /$1 [L,R=301]
change it to this line :
RewriteRule ^/$(.*) /$1 [L,R=301]
the other code works fine for me .
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.
I have modified .htaccess to remove trailing .html from my pages. htaccess looks like this:
RewriteEngine on
RewriteBase /
RewriteCond %{http://www.mydomain.co.uk} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://www.mydomain.co.uk/$1 [R=301,L]
I also added the following at the top of the .htaccess to set up a custom 404 page and stop indexing:
ErrorDocument 404 /notfound.html
Options -Indexes
The rewrite rule works perfectly. So does the anti-indexing. However the 404 page gives me this error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster#mydomain.co.uk and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
If I remove the rewriterule then the 404 page works fine. I don't know a lot about this kind of stuff and was wondering what to do to be able to get both aspects to work correctly? Can anyone help please?
(PS: I read this answer and think it might apply to me - but didn't understand it at all.)
Just wanted to let you know I found a solution for this:
ErrorDocument 404 /notfound.html
Options -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/\ ]+/)*[^.\ ]+\.htm\ HTTP/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(([^/]+/)*[^.]+)\.htm$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.html [L]
Works great!
i am using this code in the .htaccess-File to rewrite for example /home to /home.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
but how can i do this and at the same time when the server gets a request for /home.php
rewrite it so the file will not be found. I only want to allow access with /home and
not with /home.php but still use the file with it's extension.
Using this .htaccess works in general:
ErrorDocument 404 /404_error.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{THE_REQUEST} \.php[\s?/] [NC]
RewriteRule \.php$ - [NC,R=404,L]
But when a request that should throw 404 uses for example /whatever the custom 404 error page gets loaded. But with /whatever.php i get this:
The requested URL /test/whatever.php was not found on this server.
Additionally, a 500 Internal Server Error error was encountered while trying to use an
ErrorDocument to handle the request.
Any idea how to solve this 500 error?
P.S.: Same thing without php-extension "ErrorDocument 404 /404_error"
You can use this rule to block .php requests:
RewriteCond %{THE_REQUEST} \.php[\s?/] [NC]
RewriteRule \.php$ - [NC,R=404,L]