标签: http-status-code-404

保留原始参数的ASP.NET 404(页面未找到)重定向

我正在用一个具有不同结构的新Web应用程序替换旧的Web应用程序.

我无法更改新应用程序的虚拟目录路径,因为我的用户已经为旧应用程序添加了不同链接的书签.

假设我有一位拥有此书签的用户:

HTTP://server/webapp/oldpage.aspx数据= somedata

我的新应用程序将驻留在同一个虚拟目录中,替换旧的应用程序,但它不再是oldpage.aspx,而是具有不同的布局,但它仍然需要来自旧URL的参数.

所以,我已经设置将404错误重定向到redirectfrombookmark.aspx,在那里我决定如何处理请求.

问题是,我收到的唯一参数是"aspxerrorpath =/webapp/oldpage.aspx",而不是"data"参数,我需要它来正确处理请求.

知道如何在404处理程序中获取完整的"原始"URL吗?

编辑:阅读答案,看起来我没有提出足够明确的问题:

  1. 用户已经为许多不同的页面(oldpage1,oldpage2等)添加了书签,我应该平等地处理它们.
  2. 每个旧页面的参数几乎相同,我只需要一个特定的参数.
  3. 我想重新使用"新"应用程序的"旧"虚拟目录名称.
  4. 搜索机器人等不是一个问题,这是带有动态内容的内部应用程序,它经常过期.

问题是 - 我可以这样做,而不是在我的"新"应用程序中使用旧名称创建一堆空页面,并在其OnLoad中创建Request.Redirect.即可以使用404机制或Global.asax中的某些事件处理等来完成.

asp.net error-handling redirect http-status-code-404

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

Django:返回404状态代码的自定义404处理程序

我正在处理的项目有一些需要传递给每个视图的数据,所以我们有一个render_to_response被调用的包装器master_rtr.好.

现在,我需要404页面来完成这个.根据说明,我创建了一个custom_404调用master_rtr 的自定义404处理程序(巧妙地调用).一切看起来都不错,但我们的测试都失败了,因为我们收到了200 OK.

所以,我试图弄清楚如何返回404状态代码.这里似乎是一个HttpResponseNotFound类还挺我想要什么,但我不太清楚如何构建所有的废话,而不是使用render_to_response.或者更确切地说,我可能想出来,但似乎他们必须是一个更容易的方式; 在那儿?

代码的适当部分:


 def master_rtr(request, template, data = {}):
  if request.user.is_authenticated():
   # Since we're only grabbing the enrollments to get at the courses, 
   # doing select_related() will save us from having to hit database for
   # every course the user is enrolled in
   data['courses'] = \
    [e.course for e in \
     Enrollment.objects.select_related().filter(user=request.user) \
     if e.view]
  else:
   if "anonCourses" in request.session:
    data['courses'] = request.session['anonCourses']
   else: …
Run Code Online (Sandbox Code Playgroud)

django http-status-code-404

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

HTTP 404 - 找不到文件Internet Explorer V6

我有ang 404代码,如果找不到页面,将重定向到该网站.它在firefox中正常工作.但是,当我使用Internet Explorer v6时.该网站将获得和错误措施:"HTTP 404 - 文件未找到Internet Explore".我怎样才能解决这个问题?任何帮助表示赞赏

谢谢

php windows internet-explorer http-status-code-404

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

PHP if语句与isset不起作用

我认为这是简单的代码,但这不能按预期工作:

$id = $_GET['id'];
if (!isset($id)){
    header("HTTP/1.1 404 not found");
    include("404.php");
}
else {
    include('includes/functions.php'); 
}
Run Code Online (Sandbox Code Playgroud)

所以我从URL获取了get参数但我没有收到404错误?

有任何想法吗?

php http-status-code-404

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

Rails,开发环境和错误页面

我做了一个简单的应用程序,我想测试404,500等http页面的错误.我已经在我的环境/ development.rb中将config.consider_all_requests_local更改为false但我仍然遇到了一些问题,所以我想问你几个问题......

  1. 如果我输入不合适的东西,就像http://localhost:3000/products/dfgdgdgdgfd我仍然看到旧的"未知行动"网站.但是,如果我输入我的电脑的本地IP地址.http://192.168.1.106:3000/products/dfgdgdgdgfd我可以从公共文件夹中看到404错误页面.为什么会这样?

  2. 我知道,如果我将我的小项目部署到某个地方而不是我的应用程序将使用生产模式,如果发生任何错误,将显示404或500页面.但是,如果我想让这些错误页面更具动态性(例如,在使用带有常用产品列表的布局时呈现错误消息)或者只是将它们重定向到主页面,该怎么办?

2.1.我发现的第一个解决方案是在应用程序控制器中使用rescue_from方法:

unless Rails.application.config.consider_all_requests_local
   rescue_from Exception, :with => :render_error
   rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
   rescue_from AbstractController::ActionNotFound, :with => :render_not_found
   rescue_from ActionController::RoutingError, :with => :render_not_found
   rescue_from ActionController::UnknownController, :with => :render_not_found
   rescue_from ActionController::UnknownAction, :with => :render_not_found
end
.
.
.
private
def render_error exception
  Rails.logger.error(exception)
  redirect_to root_path
  #or 
  # render :controller=>'errors', :action=>'error_500', :status=>500
end

def render_not_found exception
  Rails.logger.error(exception)
  redirect_to root_path
  #or 
  # render :controller=>'errors', :action=>'error_404', :status=>404
end
Run Code Online (Sandbox Code Playgroud)

...但该代码在任何情况下都不起作用.

2.2.第二个解决方案是放置match "*path" , :to => "products#show", …

development-environment http-status-code-404 ruby-on-rails-3

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

使用.htaccess"欺骗"404找不到错误

我有.htaccess当前设置为重写任何没有句点或斜线的东西到等效的.php扩展名(所以"foo"内部拉出"foo.php")通过以下方式:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !(.*)\.php
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/.]+)$ $1.php [L,NS]
Run Code Online (Sandbox Code Playgroud)

但是,我想直接请求"foo.php"返回404,就好像文件不存在一样(就像有人试过"foo.asp"或"foo.blargh").我知道有[F]和[G]标志,但我不想要"禁止"(403)或"消失"(410),因为那些是不存在的文件返回的结果(404).

有没有办法做到这一点?

更新1

我试过了

RewriteCond %{REQUEST_FILENAME} \.php$
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.php\ HTTP/
RewriteRule ^(.*)$ /error.php?e=404 [R=404,L,NS]
Run Code Online (Sandbox Code Playgroud)

哪个有效...直到我尝试使用ErrorDocument处理程序.假设我的文档根目录中有"error.php",那么ErrorDocument 404 /error?e=404(我也尝试过使用error.php等)的任何内容都会反复出错

未找到

在此服务器上找不到请求的URL /foo.php.

此外,尝试使用ErrorDocument处理请求时遇到500内部服务器错误错误.

...但仅在尝试访问实际存在的.php页面时(例如foo.php); 任何访问实际不存在的页面的尝试(因此不会触发我的第二次重写规则)都会转到ErrorDocument处理程序指定的页面.

.htaccess mod-rewrite apache2 http-status-code-404

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

mod重写删除文件扩展名,添加尾部斜杠,删除www并重定向到404,如果没有文件/目录可用

我想在我的.htaccess文件中创建重写规则来执行以下操作:

  • 通过domain.com/abc.php访问时:删除文件扩展名,附加一个尾部斜杠并加载abc.php文件.重写后url应如下所示:domain.com/abc/

  • 通过domain.com/abc/访问时:保留原样并加载abc.php

  • 通过domain.com/abc访问时:追加尾随斜杠并加载abc.php.重写后url应如下所示:domain.com/abc/

  • 删除www

  • 当访问的URL无法解析为文件夹或文件时重定向到404页面(404.php),例如访问domain.com/nothingthere.php或domain.com/nothingthere/或domain.com/nothingthere时

  • 将一些永久的301重定向从旧网址转换为新网址(例如domain.com/abc.html到domain.com/abc/)

所有的php文件都位于文档根目录中,但如果有一个解决方案可以使域名(如果加载domain.com/abc/def.php)的域名也能正常运行,那么它就会很棒好吧,但没有必要

所以这就是我现在拥有的东西(从网络上的各种来源和样本中汇集而成)

<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  # redirect from www to non-www
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

  # remove php file extension
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
  RewriteRule (.*)\.php$ /$1/ [L,R=301]

  # add trailing slash
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^.*[^/]$ /$0/ [L,R=301]

  # resolve urls to matching php files 
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule (.*)/$ $1.php [L]
Run Code Online (Sandbox Code Playgroud)

有了这个,前四个要求似乎有效,无论我输入domain.com/abc.php,domain.com/abc/还是domain.com/abc,最终的URL总是最终成为domain.com/abc/和domain. com/abc.php已加载.

当我输入一个解析为不存在的文件的URL时,我收到错误310(重定向循环),当真正加载404页面时.另外,如果子文件夹工作,我没有尝试过,但正如我所说,这是低优先级.我很确定我可以在没有任何问题的情况下为传统网址重新发送永久301重定向,只是想提及它.所以真正的问题实际上是非工作的404页面.

url .htaccess mod-rewrite url-rewriting http-status-code-404

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

静态网页的网址重写规则-使用带有其他参数的网址后返回404

我使用IIS7的URL重写模块-因为很少静态文件的URL重写。

基本上我将/ pretty-url映射到/real-file-name.html

到目前为止,这很简单。

但是在将查询字符串添加到漂亮的url之后,它会抛出404状态代码。到目前为止,我还没有找到解决此问题的任何选择。有什么建议吗,或者我做错了什么?

配置如下:

<rewriteMaps>
  <rewriteMap name="CoolUrls">
<add key="/pretty-url" value="/real-file.html" />
    ... and so on ...
  </rewriteMap>
</rewriteMaps>
Run Code Online (Sandbox Code Playgroud)

和:

<rules>
  <clear />
    <rule name="Rewrite rule for CoolUrls" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{CoolUrls:{REQUEST_URI}}" pattern="(.+)" />
      </conditions>
      <action type="Rewrite" url="{C:1}" appendQueryString="true" />
    </rule>
</rules>
Run Code Online (Sandbox Code Playgroud)

任何带有查询的请求(?标记后的任何参数)都以404状态码结束。

iis iis-7 url-rewriting url-parameters http-status-code-404

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

htaccess的自定义目录,错误404

我有一个网站,每个用户的cms安装在不同的目录中,其结构类似于:

/ (root)
/cms_user1/
/cms_user1/404.php
/cms_user1/.htaccess
/cms_user2/
/cms_user2/404.php
/cms_user2/.htaccess
Run Code Online (Sandbox Code Playgroud)

每个.htaccess文件中都有:

ErrorDocument 404 /404.php
Run Code Online (Sandbox Code Playgroud)

问题是,这样,页面404.php不会加载到/cms_client1/404.php上,而是加载到根目录中,即/404.php

有一种方法可以自动将404.php加载到用户目录中,而无需指定目录名

PS:到目前为止,我发现的唯一方法是在每个.htaccess中指定目录名称(在我的情况下,这不是最佳选择,因为我必须编辑每个htaccess),如下所示:

ErrorDocument 404 /directory/404.php
Run Code Online (Sandbox Code Playgroud)

.htaccess http-status-code-404

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

如何从jQuery $ .ajax调用servlet而不会出现HTTP 404错误

我试图使用ajax调用调用servlet,如下所示:

$.ajax({
  url: 'CheckingAjax',
  type: 'GET',
  data: { field1: "hello", field2 : "hello2"} ,
  contentType: 'application/json; charset=utf-8',
  success: function (response) {
    //your success code
    alert("success");
  },
  error: function (errorThrown) {
    //your error code
    alert("not success :"+errorThrown);
  }                         
});
Run Code Online (Sandbox Code Playgroud)

但是,它会error起作用并显示警报:

没有成功:没找到

这是怎么造成的,我该如何解决?

ajax url jquery servlets http-status-code-404

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