本地主机上的404错误 [英] 404 error on localhost
问题描述
我正在尝试使用一些ajax发送一些电子邮件.我在使用冷聚变之前就已经做到了,没有问题.
I am trying to use some ajax to send some email. I have done this before using cold fusion and had no issue.
我遇到的是 localhost 找不到目录中的文件.实际上,该文件与index.php位于同一目录中,这没有问题.但是,它在我的send.php文件上给了我一个 404错误文件.我什至尝试通过地址栏直接转到页面,但找不到文件. 如果我输入文件路径,即-file:///C://xampp/htdocs/3H-Web-Wlements/send.php,它将显示代码.
What I am running into is that localhost is not finding a file that is clearly in the directory. In fact the file sits in the same directory as index.php which is finds no problem. However it gives me a 404 error file not found on my send.php file. I have even tried to go directly to the page via the address bar and it does not find the file. If I put in the file path ie - file:///C://xampp/htdocs/3H-Web-Wlements/send.php it will display the code.
但是,当我上传到活动服务器时,它没有任何问题.
However when I upload to my active server it has no issues.
我在这里想念什么?
这是日志中的错误: [2015年9月23日星期三19:33:34.295785] [:错误] [pid 2552:tid 1752] [客户端:: 1:63670]脚本'C:/xampp/htdocs/index.php'找不到或无法统计,引荐来源: http://localhost/3H-Web-Wlements/
Here is the error from the log: [Wed Sep 23 19:33:34.295785 2015] [:error] [pid 2552:tid 1752] [client ::1:63670] script 'C:/xampp/htdocs/index.php' not found or unable to stat, referer: http://localhost/3H-Web-Wlements/
我配置错误或什至未配置吗?
就像我说的.它可以在我的活动服务器上运行,但仅在本地主机上失败.
Do I have something mis-configured or even not configured?
Like I said. It works on my active server but fails on localhost only.
我的send.php代码
my send.php code
<?php
/*
**************************************
* *
* Config here *
* *
**************************************
*/
$to = 'xxx@gmail.com';
$subject = 'Message from website';
$siteName = "xxx";
/*
*************************************************************
* *
* Don't Change below code, if you don't know php. *
* *
*************************************************************
*/
$name = $_POST['contactName'];
$mail = $_POST['contactEmail'];
$subject = $_POST['contactWebsite'];
$note = $_POST['contactMessage'];
$ipAdd = $_POST['contactIp'];
if (isset($name) && isset($mail) && isset($note)) {
// $mailSub = '[Contact] [' . $siteName . '] '.$subject;
$body = 'Sender Name: ' . $name . "\n\n";
$body .= 'Sender IP: ' . $ipAdd . "\n\n";
$body .= 'Sender Mail: ' . $mail . "\n\n";
$body .= 'Website: ' . $subject . "\n\n";
$body .= 'Message: ' . $note;
$message = $body;
$header = 'From: ' . $mail . "\r\n";
$header .= 'Reply-To: ' . $mail . "\r\n";
$header .= 'X-Mailer: PHP/' . phpversion();
// mail($to, $mailSub, $body, $header);
mail($to, $subject, $message, $headers);
}else{
echo '0';
}
?>
推荐答案
基于您提供的错误消息以及您在localhost上浏览的URL的晦涩感,我怀疑问题的根本原因在于两个不同的原因.在开发服务器和生产服务器上设置的文档根目录.
Based on the error message you provided and the obscurity of the URL you are navigating to on localhost, I suspect the root cause of your issue stems from having two different document roots set up on your development server and production server.
如果对的话,可以通过将开发服务器的文档根目录从C://xampp/htdocs/
更改为C://xampp/htdocs/3H-Web-Wlements/
来解决.使用此设置,服务器将尝试从3H-Web-Wlements/
而不是htdocs/
服务index.php
.
If I'm right, this can be fixed by changing your development server's document root from C://xampp/htdocs/
to C://xampp/htdocs/3H-Web-Wlements/
. With this set, the server will attempt to serve index.php
from 3H-Web-Wlements/
instead of from htdocs/
.
可以在Apache的配置文件(通常称为httpd.conf
)中设置文档根目录设置.如果您使用的是XAMPP或MAMP之类的开发设置,则可能会在控制面板中有一个按钮来访问httpd.conf.
The document root setting can be set within Apache's configuration file typically called httpd.conf
. If you're using a development setup like XAMPP or MAMP, you likely have a button in the control panel to get to httpd.conf.
更改后的设置应如下所示:
The setting should look like this after the change:
DocumentRoot C://xampp/htdocs/3H-Web-Wlements/
进行更改后,您将需要重新启动Web服务器以使更改生效.
After making the change, you will need to restart your web server for the changes to take effect.
这篇关于本地主机上的404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!