我只在本地cassini Web服务器上测试我的应用程序,我觉得很奇怪.
一个索引页面以默认方式工作,第二个显示404,但使用完整版控制器/索引 - 工作正常.我发现的唯一区别是,在第一个示例中,最后没有斜杠,并且存在第二个斜杠,但是指向已损坏的链接没有斜杠.
我有一些页面,我不希望用户能够直接访问.
我有这个功能,我提出了哪些工作:
function prevent_direct_access()
{
if($_SERVER['REQUEST_URI'] == $_SERVER['PHP_SELF'])
{
//include_once('404.php');
header("Location: 404.php");
}
}
Run Code Online (Sandbox Code Playgroud)
这正是我想要的,URL不会改变但内容会改变.但是我想知道是否有一些东西我需要添加来告诉搜索引擎这是一个404而不是索引它.请记住,我不希望URL改变.
谢谢!
有没有办法从块或模板中检查您所在的页面是否为404?
我有关于Codeigniter的这个问题,遗憾的是,本网站关于此问题的其他帖子对我没有帮助,或者我没有很好地应用它.
编辑*添加截图:


我的目录结构:
正如标题所说,当我打字时
http://mysite.com/folder/index.php
它输出找不到的页面404.但是,当我输入http://mysite.com/scheduler/index.php/BS时,它显示"这是一个BS文件",因为我使用下面的代码回应它.
BS.php
function index($flag = NULL)
{
echo "This is a BS File.";
}
Run Code Online (Sandbox Code Playgroud)
routes.php文件
$route['default_controller'] = "BS";
$route['scaffolding_trigger'] = "";
Run Code Online (Sandbox Code Playgroud)
的index.php
error_reporting(E_ALL);
$system_folder = "system";
$application_folder = "application";
if (strpos($system_folder, '/') === FALSE)
{
if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
{
$system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
}
}
else
{
// Swap directory separators to Unix style for consistency
$system_folder = str_replace("\\", "/", $system_folder);
}
define('EXT', …Run Code Online (Sandbox Code Playgroud) 我编写了GAE云端点API,并已成功将它们部署到App Engine.API在本地以及在App Engine上部署后成功运行.
生成云端点后,我尝试在我的Android客户端中调用其中一个API,并抛出"未找到GoogleJSONResponseException 404"异常.在API方法中,我使用HttpURLConnection和JAXB unmarshaller来调用URL并解组XML响应.代码如下:
String uri=<some url>;
URL url = new URL(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "application/xml");
JAXBContext jc = JAXBContext.newInstance(MyResponse.class);
InputStream xml = connection.getInputStream();
response = (MyResponse) jc.createUnmarshaller().unmarshal(xml);
connection.disconnect();
Run Code Online (Sandbox Code Playgroud)
为什么这只在尝试使用端点客户端库从Android客户端调用时不起作用?难道我做错了什么?
注意:我在同一个Android客户端中调用了另一个API,它只是将数据插入到数据存储区中,并且工作正常
LogCat控制台如下所示:
06-17 11:44:49.081: W/System.err(2035): com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
06-17 11:44:49.081: W/System.err(2035): Not Found
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:111)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:38)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:314)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1060)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:412)
06-17 11:44:49.081: W/System.err(2035): at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:345) …Run Code Online (Sandbox Code Playgroud) cloud google-app-engine android endpoint http-status-code-404
我是新手,所以我会尝试清楚地解释自己.
我正在从自定义404页面进行301重定向.现在我开始工作了我的问题更多是关于谷歌如何对待它.因为我们去404页面谷歌只是将它记录为40页或者它实际记录301?正如我所说,我是新手,并通过谷歌试图找到答案.
无论如何,任何帮助或评论都会受到极大关注.提前致谢
我有一个文件index.php,.htaccess与此代码在同一级别a :
ErrorDocument 404 index.php
Run Code Online (Sandbox Code Playgroud)
当我生成一个未找到的错误时,打印一个带有文件名的页面,因此,在这种情况下,我只看到index.php文字文本.我想要的显然是重定向到主页.
对这个问题有什么想法吗?
www\site
-index.php
-.htaccess
Run Code Online (Sandbox Code Playgroud) 我已经尝试了404_override和MY_Exceptions来显示自定义错误视图.有人可以帮我吗?
这是404_override代码
routes.php文件
$route['404_override'] = 'error/index';
Run Code Online (Sandbox Code Playgroud)
Error.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Error extends CI_Controller {
public $user_id ='';
function __construct()
{
parent::__construct();
$this->load->library('login.php');
$user_Details = $this->login_library->get_user_details();
$this->user_id = $user_Details['user_id'];
}
public function index()
{
$this->output->set_status_header('404');
$this->output->set_status_header('404');
$this->load->view('view_header',$this->user_id);
$this->load->view('view_404');
$this->load->view('view_footer',$this->user_id);
}
}
Run Code Online (Sandbox Code Playgroud)
这是My_Exceptions代码
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Exceptions extends CI_Exceptions{
function MY_Exceptions(){
parent::CI_Exceptions();
$this->CI =& get_instance();
}
function show_404($page=''){
echo $heading = "404 Page Not Found";
echo $message …Run Code Online (Sandbox Code Playgroud) error-handling routing codeigniter exception http-status-code-404
当我覆盖urls.py中的handler404和handler500时,如下所示:
from myapp.views import not_found_view
handler404 = not_found_view
handler500 = not_found_view
Run Code Online (Sandbox Code Playgroud)
并调用raise Http404()我的中间件,我看到我的404页面.
当我都删除handler404,并handler500从我urls.py和raise Http404()我的中间件,我看到我的默认的500错误页面(从Django的套装) -因此我试图设置自定义模板404的理由上使用raise Http404()的.
现在我的问题:当我删除handler500并且只设置handler404时,我也会看到HTTP 500页面!:|
为什么我handler500被叫了raise Http404()?
我在多个应用程序中有多个模板目录,我尝试404.html在我的主应用程序中放置一个包含设置和另一个"普通"应用程序,但这不起作用..
我已经设置DEBUG来False为好.
希望有人能回答我的问题!
from flask import g, request, session, render_template, flash, redirect, url_for
from flask import current_app as app
@app.route('/')
def home():
return 'this works'
from flask_restful import Resource, Api
from app.extensions import api
class HelloWorld(Resource):
def get(self):
return {'Hello': 'World'}
api.add_resource(HelloWorld, '/test') # Getting a 404 for this route on http://127.0.0.1:5000/test
Run Code Online (Sandbox Code Playgroud)
扩展程序设置api变量:
api = Api()
api.init_app(app)
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么在尝试访问api资源时会收到404错误?
php ×3
codeigniter ×2
python ×2
routing ×2
.htaccess ×1
android ×1
asp.net-mvc ×1
cloud ×1
controller ×1
django ×1
endpoint ×1
exception ×1
flask ×1
magento ×1
routes ×1
seo ×1
url-routing ×1