标签: http-status-code-404

使用javascript来检测在iframe中显示之前是否存在url

我正在使用javascript将动态网址传递给iframe src.但有时网址不存在,我怎么能事先检测到不存在的网址,以便我可以隐藏带有404错误的iframe.

javascript iframe http-status-code-404

35
推荐指数
5
解决办法
10万
查看次数

Netlify 在页面刷新时呈现 404(使用 React 和 react-router)

我已经使用 Netlify 部署了我的站点,但在路由方面遇到了问题。

这是我的网站:https : //redux-co.netlify.com/

还有我的 GitHub 仓库:https : //github.com/jenna-m/redux-co

具体来说,如果用户导航到主页以外的任何页面并刷新页面,则默认 Netlify 404 呈现。从 404 页面,如果我导航回主页并刷新,则呈现主页。

此外,我的自定义 404 页面无法像我打开时那样工作localhost:3000,但我想在处理我的自定义 404 组件之前先弄清楚这个刷新问题。

我正在使用 React 和 react-router,我知道由于我使用的是 react-router,我的网站不会立即部署。


这是我的_redirects文件,它在/public我的index.html文件所在的文件夹中:

/*    /index.html   200
Run Code Online (Sandbox Code Playgroud)

这是我“build”位于package.json

…
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build && cp build/index.html build/404.html",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }
…
Run Code Online (Sandbox Code Playgroud)

我读过其他人遇到过这种情况以及他们为克服这个问题所做的工作。这是我到目前为止所引用的……

https://www.freecodecamp.org/news/how-to-deploy-a-react-application-to-netlify-363b8a98a985/

https://hugogiraudel.com/2017/05/13/using-create-react-app-on-netlify/

这个人使用的是 Vue 而不是 React,但我还是尝试了这些解决方案:

https://github.com/vuejs/vuepress/issues/457#issuecomment-390206649

https://github.com/vuejs/vuepress/issues/457#issuecomment-463745656

http-status-code-404 reactjs react-router netlify

34
推荐指数
4
解决办法
1万
查看次数

Nginx错误页面 - 适合所有人的一个位置规则?

拥有以下nginx vhost配置:

server {
    listen 80;
    listen 443 ssl;
    server_name default;
    root /var/www/default/html;
    error_log /var/www/default/log/error.log;
    access_log /var/www/default/log/access.log;
    ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
    ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;

    autoindex on;
    index index.html index.php;

    location / {
        try_files $uri $uri/ @php;
    }

    location @php {
        rewrite ^/(.*)/?$ /index.php/$1 last;
    }

    location ~* /(?:[.]|.*[.](?:bak|fla|inc|ini|log|psd|sh|sql|swp)|(?:file|upload)s?/.*[.](?:php)) {
        deny all;
    }

    location ~* [.](?:php) {
        fastcgi_buffer_size             128k;
        fastcgi_buffers                 4 256k;
        fastcgi_busy_buffers_size       256k;
        fastcgi_connect_timeout         30;
        fastcgi_ignore_client_abort     off;
        fastcgi_index                   index.php;
        fastcgi_intercept_errors        on;
        fastcgi_pass                    unix:/var/run/php5-fpm.sock;
        fastcgi_read_timeout            60;
        fastcgi_send_timeout            60;
        fastcgi_split_path_info         ^(.+[.]php)(/.*)$;
        fastcgi_temp_file_write_size    256k;

        include /etc/nginx/fastcgi_params; …
Run Code Online (Sandbox Code Playgroud)

error-handling nginx http-status-code-404

32
推荐指数
1
解决办法
5万
查看次数

我怎样才能获得NSURLResponse身体?

我正在编写一个与服务器连接的应用程序NSURLConnection.

在委托方法中didreceiveresponse,如果状态代码是404,我取消连接,我想显示一条消息,其中包含在服务器中生成的自定义错误.

问题是,从响应对象,我只能得到状态码,标题,mimetype等,但没有身体.

我如何从中获取身体信息NSURLResponse

objective-c nsurlconnection nsurlrequest http-status-code-404

31
推荐指数
1
解决办法
4万
查看次数

将404重定向到类似的网址

我有一个有故事的网站.我可以在多个类别中拥有多种类型的故事,例如:

  • 孩子
  • 浪漫
  • 科幻
  • 行动
  • thriler
  • 任务

可以使用以下网址访问这些故事:

www.example.com/action/story-name-action/
www.example.com/romance/story-name-romance/
Run Code Online (Sandbox Code Playgroud)

第一个参数(动作)和第二个(故事名称动作)使用规则重定向.htaccess.这部分工作正常.

最近,我从不同的网站得到了几十个404,这就是我想要做的但我不知道如何:

如果有人输入,例如:/action/story-nme-ction,我想重定向到:action/story-name-action/

有没有一种有效的方法来实现它?

php mysql .htaccess url-rewriting http-status-code-404

31
推荐指数
3
解决办法
1518
查看次数

CakePHP 2.0 - 如何制作自定义错误页面?

我读到AppError类现在是为了向后兼容,应该使用Exceptions.如何为404错误或完全自定义错误等内容创建自定义错误页面?

php cakephp http-status-code-404 cakephp-2.0

31
推荐指数
4
解决办法
4万
查看次数

来自jquery的sourceMappingURL在apache中生成404错误

浏览apache日志并发现有趣的事情:

当用户访问我包含jquery的任何页面时,apache会尝试获取jquery-xxx.min.map文件并因404错误而失败.这是一个例子:

xxx.xxx.xxx - - [Date:TIME +0000] "GET /js/lib/jquery-1.10.2.min.map HTTP/1.1" 404 3134 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"
Run Code Online (Sandbox Code Playgroud)

这并不奇怪,因为我显然没有这个min.map文件.我不喜欢这种行为.

查看jquery源代码,我发现了

/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery-1.10.2.min.map
Run Code Online (Sandbox Code Playgroud)

首先,这个sourceMappingURL在评论中,没有其他命中.当我刚删除它时,404错误消失了.

我毫不怀疑来自jquery的人知道他们在做什么,但任何人都可以解释我:

  • 这个sourceMappingURL创建了一些以404结尾的连接是什么意思?

  • 当我删除这条线时,我失去了什么?

我能找到的唯一相关的事情是这个链接,据我所知(如果我错了,请告诉我):

  • 它在IE中产生一些错误(我通过Chrome查看)
  • 它已被弃用(我正在使用最新版本的jQuery)
  • 它用于调试目的(还没有理解为什么调试目的)

jquery http-status-code-404

31
推荐指数
1
解决办法
2万
查看次数

我如何在Tomcat上的JAX-RS(Jersey)中返回HTTP 404 JSON/XML响应?

我有以下代码:

@Path("/users/{id}")
public class UserResource {

    @Autowired
    private UserDao userDao;

    @GET
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public User getUser(@PathParam("id") int id) {
        User user = userDao.getUserById(id);
        if (user == null) {
            throw new NotFoundException();
        }
        return user;
    }
Run Code Online (Sandbox Code Playgroud)

如果我请求不存在的用户,例如/users/1234" Accept: application/json",则此代码返回一个HTTP 404人们期望的响应,但返回Content-Type设置为text/htmlhtml的正文消息.注释@Produces被忽略.

这是代码问题还是配置问题?

java rest tomcat http-status-code-404 jersey-2.0

31
推荐指数
2
解决办法
4万
查看次数

返回404错误ASP.NET MVC 3

我尝试了以下两件事让页面返回404错误:

public ActionResult Index()
{
    return new HttpStatusCodeResult(404);
}

public ActionResult NotFound()
{
    return HttpNotFound();
}
Run Code Online (Sandbox Code Playgroud)

但他们两个只是渲染一个空白页面.如何从ASP.NET MVC 3中手动返回404错误?

http-status-code-404 asp.net-mvc-3

30
推荐指数
4
解决办法
4万
查看次数

如何强制将所有404(或每个页面,无论是否无效)重定向到主页?

目前,每个无效页面都是500(内部服务器错误),因为我可能搞砸了我的服务器块配置.

我决定暂时关闭我的网站,并创建了一个简单的单页感谢主页.但旧链接和外部网站仍在尝试访问网站的其他部分,这些部分已不复存在.

如何强制将所有非主页(任何无效的URL)重定向到主页?

我尝试使用以下块,但它不起作用:

location / {
    try_files $uri $uri/ $document_uri/index.html;
}
Run Code Online (Sandbox Code Playgroud)

我当前的配置是(我现在甚至不提供PHP文件,即主页是简单的html):

server {
    server_name www.example.com example.com;
    access_log /srv/www/example.com/logs/access.log;
    error_log /srv/www/example.com/logs/error.log;
    root /srv/www/example.com/public_html;
    index index.php index.html;

    location / {
        try_files $uri $uri/ $document_uri/index.html;
    }

    # Disable favicon.ico logging
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    # Allow robots and disable logging
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    # Enable permalink structures
    if (!-e $request_filename) {
        rewrite . /index.php last;
    }

    # Handle …
Run Code Online (Sandbox Code Playgroud)

redirect nginx http-status-code-404

30
推荐指数
4
解决办法
6万
查看次数