php 未找到对象!在此服务器上找不到请求的 URL。本地主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15046543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Object not found! The requested URL was not found on this server. localhost
提问by user2089405
I have a typical set up A,M,P and i am just doing some testing on my localhost server for setting up a webpage. I'm a bit new to php and dynamic sites so I'm muddling my way though. So I am at an impasse here. Whenever I attempt to view the page in the browser and click on the links I get this error:
我有一个典型的设置 A、M、P,我只是在我的 localhost 服务器上做一些测试来设置网页。我对 php 和动态网站有点陌生,所以我很困惑。所以我在这里陷入了僵局。每当我尝试在浏览器中查看页面并单击链接时,我都会收到此错误:
Object not found! The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error. If you think this is a server error, please contact the webmaster. Error 404 localhost Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
未找到对象!在此服务器上找不到请求的 URL。引用页面上的链接似乎有误或已过时。请将该错误告知该页面的作者。如果您认为这是服务器错误,请联系网站管理员。错误 404 本地主机 Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
my url looks like this: http://localhost/test/content/home
here is the code for my index.php page and my nav.php page
这是我的 index.php 页面和我的 nav.php 页面的代码
first index.php
第一个 index.php
<?php
include('Config/setup.php');
?>
<?php
if(isset($_GET['page']) && $_GET['page'] == !'') {
$pg = $_GET['page'];
} else {
$pg = 'home';
}
#var_dump($pg);
#exit;
?>
<!DOCTYPE HTML>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>FTS</title>
<link href="css/Styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="header temp_Block">
<?php include('templates/header.php');?>
</div>
<div class="main_nav temp_Block">
<?php include('templates/main_nav.php');?>
</div>
<div class="main_Content temp_Block">
<?php include('Content/'.$pg.'.php');?>
</div>
<div class="footer temp_Block">
<?php include('templates/footer.php');?>
</div>
</body>
</html>
Here is my nav.php
这是我的 nav.php
<?php include('Config/setup.php')?>
<a href="/test/content/home">home</a>
<a href="/test/content/freestuff">free stuff</a>
<a href="/test/content/aboutus">about us</a>
<a href="/test/content/services">services</a>
<a href="/test/content/Whatwedobetter">What we do better</a>
I thought this might be a permissions problem because /content/home.php is in a subfolder in xxamp/htdocs/test. But I'm not entirely sure. I could test this on a hosting site which I have but the 404 error makes me think it might be something with localhost and not with my code.
我认为这可能是权限问题,因为 /content/home.php 位于 xxamp/htdocs/test 的子文件夹中。但我不完全确定。我可以在我拥有的托管站点上对此进行测试,但是 404 错误使我认为它可能与本地主机有关,而不是与我的代码有关。
回答by hakim
mostly this kind of error is caused by missing an .htaccess file in your root wordpress directory , however in order to check that , get in touch directly to the permalink structure and try to change your permalink and hit save , once you find the same error you should directly create an .htaccess file under wordpress root and make its first permissions to 777 , then refresh your site an click save change on your permalink , once your site continue to run correctly as you were expected , you should right away comeback to your .htaccess and change it to 644 in order to secure your site , i believe that this happened in most wordpress permalink settings , hopefully it would be helpful for anyone who meet this kind of issue .
大多数此类错误是由于在您的 wordpress 根目录中缺少 .htaccess 文件引起的,但是为了检查这一点,请直接联系永久链接结构并尝试更改您的永久链接并点击保存,一旦您发现相同的错误。您应该直接在 wordpress 根目录下创建一个 .htaccess 文件并将其第一个权限设置为 777 ,然后刷新您的站点并单击永久链接上的保存更改,一旦您的站点继续按预期正确运行,您应该立即返回到您的.htaccess 并将其更改为 644 以保护您的站点,我相信这发生在大多数 wordpress 永久链接设置中,希望这对遇到此类问题的任何人都有帮助。
回答by Sakthi Karthik
You are not specified your project as right way.
您没有以正确的方式指定您的项目。
- So run your
XAMPP control panelthen start theapacheandMySQL - Then note the ports.
- For Example PORT 80: then you type your browser url as
localhost:80\press enter now your php basic Config page is visible. - Then create any folder on
xampp\htdocs\YourFloderNameThen create php file then save it and go to browser then type itlocalhost\YourFolderNamenow it listed the files click the file and it runs.
- 所以运行你的
XAMPP control panel然后启动apache和MySQL - 然后记下端口。
- 例如 PORT 80: 然后你输入你的浏览器 url
localhost:80\并按回车键,现在你的 php 基本配置页面是可见的。 - 然后创建任何文件夹
xampp\htdocs\YourFloderName然后创建php文件然后保存它并转到浏览器然后输入它localhost\YourFolderName现在它列出了文件单击该文件并运行。
回答by Ahmed Bakri
write in file config
写入文件配置
$config['base_url'] = 'http://localhost:8000/test/content/home/';
回答by Parkofadown
One thing I found out is that your folder holding your php/html files cannot be named the same name as the folder in your HTDOCS carrying your project.
我发现的一件事是,您保存 php/html 文件的文件夹不能与您的 HTDOCS 中包含您的项目的文件夹同名。
回答by pratham kesarkar
Simply my project wasn't in htdocs thats why it was showing me an this error make sure you put your project in HTdocs not in directory inside it
只是我的项目不在 htdocs 中,这就是为什么它向我显示此错误的原因,请确保您将项目放在 HTdocs 中,而不是在其中的目录中
回答by Vis
I also had same error but with codeigniter application. I changed
我也有同样的错误,但使用 codeigniter 应用程序。我变了
- my base URL in config.php to my localhost path
in htaccess I changed RewriteBase /"my folder name in htdocs"
and I able to login to my application.
- 我在 config.php 中的基本 URL 到我的本地主机路径
在 htaccess 中,我更改了 RewriteBase /"我在 htdocs 中的文件夹名称"
我可以登录我的应用程序。
Hope it might help.
希望它可能会有所帮助。
回答by mkungla
First check what your php error reports tells you. And define application wide root at the biginning of your index.php
首先检查你的 php 错误报告告诉你什么。并在 index.php 的 biginning 定义应用程序范围的根
define ('APPROOT', realpath(dirname(__FILE__)));
and then use it to include you files
然后用它来包含你的文件
include(APPROOT.'templates/header.php');
and so on... And to you have you .htaccess rewrite rule?
等等......你有你的.htaccess重写规则吗?
回答by Matt Clark
Is the Config/setup.phpfile actually in /test/content/home/or is in your document root? it is best to make all references relative to your document root.
该Config/setup.php文件实际上/test/content/home/是在您的文档根目录中还是在您的文档根目录中?最好使所有引用都相对于您的文档根目录。
include $_SERVER['DOCUMENT_ROOT'] . "Config/setup.php";
Your current code assumes that the location of setup.phpis in /text/content/home/Config/setup.php, is this correct?
您当前的代码假定 的位置setup.php在 中/text/content/home/Config/setup.php,这是正确的吗?
回答by Dhawal
If the page you are visiting is index.php, then your url should look like
如果您访问的页面是 index.php,那么您的 url 应该是这样的
http://localhost/test/content/home/ OR http://localhost/test/content/home/index.php
not the way you specified - http://localhost/test/content/home

