http-status-code-404 interview questions
Top http-status-code-404 frequently asked interview questions
if (strstr($_SERVER['REQUEST_URI'],'index.php')) {
header('HTTP/1.0 404 Not Found');
}
Why wont this work? I get a blank page.
Source: (StackOverflow)
I have an action that takes in a string that is used to retrieve some data. If this string results in no data being returned (maybe because it has been deleted), I want to return a 404 and display an error page.
I currently just use return a special view that display a friendly error message specific to this action saying that the item was not found. This works fine, but would ideally like to return a 404 status code so search engines know that this content no longer exists and can remove it from the search results.
What is the best way to go about this?
Is it as simple as setting Response.StatusCode = 404?
Source: (StackOverflow)
I am just getting started on ASP.NET MVC so bear with me. I've searched around this site and various others and have seen a few implementations of this.
EDIT: I forgot to mention I am using RC2
Using URL Routing:
routes.MapRoute(
"Error",
"{*url}",
new { controller = "Errors", action = "NotFound" } // 404s
);
The above seems to take care of requests like this (assuming default route tables setup by initial MVC project): "/blah/blah/blah/blah"
Overriding HandleUnknownAction() in the controller itself:
// 404s - handle here (bad action requested
protected override void HandleUnknownAction(string actionName) {
ViewData["actionName"] = actionName;
View("NotFound").ExecuteResult(this.ControllerContext);
}
However the previous strategies do not handle a request to a Bad/Unknown controller. For example, I do not have a "/IDoNotExist", if I request this I get the generic 404 page from the web server and not my 404 if I use routing + override.
So finally, my question is: Is there any way to catch this type of request using a route or something else in the MVC framework itself?
OR should I just default to using Web.Config customErrors as my 404 handler and forget all this? I assume if I go with customErrors I'll have to store the generic 404 page outside of /Views due to the Web.Config restrictions on direct access. Anyway any best practices or guidance is appreciated.
Source: (StackOverflow)
If given the route:
{FeedName}/{ItemPermalink}
ex: /Blog/Hello-World
If the item doesn't exist, I want to return a 404. What is the right way to do this in ASP.NET MVC?
Source: (StackOverflow)
I have been getting the "ERROR 404.3 Not Found" for JSON file that I am calling using AJAX call on "Internet Information Services 7.5" even after I have activated all the "Application Development Features". Other than JSON file, all other files are getting loaded.
I am running an HTML page on IIS server on my local machine.
If I open the file directly then there is no problem at all. When I host the files on an online server it works fine.
Any quick help will be much appreciated.
Source: (StackOverflow)
I am new to Solr, after installing it in ubuntu 8.10, when I was trying exampledocs to index , as per this link, I got this error:
HTTP ERROR: 404 missing core name in path
This is in Jetty.
What shall I do, in order to solve this?
Source: (StackOverflow)
What is the best way to serve up proper 404's with an AngularJS app?
A little background: I'm building an Angular app and have opted to use
$locationProvider.html5Mode(true);
because I want the URLs to appear natural (and indistinguishable from a multi-page "traditional" web app).
On the server side (a simple Python Flask app), I have a catch-all handler that redirects everything to the angular app:
@app.route('/', defaults={'path': ''})
@app.route('/<path>')
def index(path):
return make_response(open('Ang/templates/index.html').read())
Now, I'm trying to figure out what to do with 404 errors. Most of the Angular apps I've seen do the following:
.otherwise({ redirectTo: '/' })
which means that there is no way they can serve up a proper 404.
However, I would much rather return a proper 404, with a 404 status code (mainly for SEO purposes).
What is the best way to handle 404s with Angular? Should I not worry about it and stick with a catch-all? Or should I remove the catch-all and serve up proper 404's on the server side?
edited for clarity
Source: (StackOverflow)
I've setup a static website on GAE using hints found elsewhere, but can't figure out how to return a 404 error. My app.yaml file looks like
- url: (.*)/
static_files: static\1/index.html
upload: static/index.html
- url: /
static_dir: static
with all the static html/jpg files stored under the static directory. The above works for files that exist, but returns a null length file if they don't. The answer is probably to write a python script to return a 404 error, but how do you set things up to serve the static files that exist but run the script for files that don't?
Here is the log from fetching a non-existent file (nosuch.html) on the development application server:
ERROR 2008-11-25 20:08:34,084 dev_appserver.py] Error encountered reading file "/usr/home/ctuffli/www/tufflinet/static/nosuch.html":
[Errno 2] No such file or directory: '/usr/home/ctuffli/www/tufflinet/static/nosuch.html'
INFO 2008-11-25 20:08:34,088 dev_appserver.py] "GET /nosuch.html HTTP/1.1" 404 -
Source: (StackOverflow)
Is it possible to create a final route that catches all .. and bounces the user to a 404 view in ASP.NET MVC?
NOTE: I don't want to set this up in my IIS settings.
Source: (StackOverflow)
Just trying out laravel 4 which I installed using composer. Have setup a virtualhost. Only the root route is working:
Route::get('/', function()
{
return View::make('hello');
});
Even this is not working
Route::get('/hello', function()
{
return View::make('hello');
});
What I am trying to hit is a TasksController
at /tasks
:
Route::resource('tasks', 'TasksController');
This is giving me 404 too.
What could I be doing wrong? I followed these instructions while installing: http://chris-schmitz.com/getting-started-with-laravel-4/
Also I do have a default .htaccess file at the root of my project:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I am on a mac using localhost.
Source: (StackOverflow)
I'm unit testing one of my directives (angularjs) using grunt/karma/phantomjs/jasmine. My tests run fine
describe('bar foo', function () {
beforeEach(inject(function ($rootScope, $compile) {
elm = angular.element('<img bar-foo src="img1.png"/>');
scope = $rootScope.$new();
$compile(elm)();
scope.$digest();
}));
....
});
but I do get these 404s
WARN [web-server]: 404: /img1.png
WARN [web-server]: 404: /img2.png
...
Although they do nothing, they do add noise to the log output. Is there a way to fix this ? (without changing karma's logLevel of course, because I do want to see them)
Source: (StackOverflow)
I've having a little issue with Django's staticfiles app.
I have added
'django.contrib.staticfiles',
to my INSTALLED_APPS and have added
STATIC_URL = '/static/'
STATIC_ROOT = '/Users/kevdotbadger/django/mylook/static/'
to my settings.py
file.
All my static files are located within the STATIC_ROOT
folder on my Mac.
Now, within my template I use
{{ STATIC_URL }}
which correctly renders to /static/
.
However
{{ STATIC_URL }}css/style.css
result in a 404 error. I'm using the 'runserver' command as the server.
Is there something I'm missing?
Source: (StackOverflow)
My cordova version is 5.0.0
I am getting a 404 error for the all ajax request made when the app is deployed on the device. On the web browser, it works fine but same app when deployed on a device does not work.
I tried adding following to solve the issue but it hasn't helped.
Config.xml
<access origin="*" />
AndriodManiest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
I also added following in my index.html file but it didn't make any difference either.
<script>
$.support.cors=true;
</script>
Anyone here has another trick to solve this issue?, Seems to be a quite common issue with phonegap but the fixes above worked in older vesion of the phonegap/cordova but non of them has worked in my case.
Any help would be great.
Source: (StackOverflow)
I'm using IIS 7.5 and I'm unable to load the less file because it gives a 404 error.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Less Tutorial</title>
<link rel="stylesheet/less" rel='nofollow' href="style.less" />
<script src="less-1.0.41.min.js"></script>
</head>
<body>
<div id="container">
<a rel='nofollow' href="#">My Anchor</a>
</div>
</body>
</html>
LESS:
@primary_color: green;
#container {
width: 200px;
height: 200px;
background: @primary_color;
}
Source: (StackOverflow)
I have a Web Api application. It works perfectly well when I tested it using the VS 2010 debugging dev server. But I now deployed it to IIS 7.5 and I am getting a HTTP 404 error when trying to access the application.
Here is my web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-FlowGearProxy-20123141219;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="true" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
Source: (StackOverflow)