php 访问 http://localhost 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9853952/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:46:58  来源:igfitidea点击:

Getting an error when I visit http://localhost

phpapachelocalhost

提问by Johnathan Au

I am trying to access localhost on my xampp via the Chrome browser but I get this error message:

我正在尝试通过 Chrome 浏览器访问 xampp 上的 localhost,但收到此错误消息:

Object not found!

The requested URL was not found on this server. If you entered the 
URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404

Apache and MySQL are turned on so I don't understand.

Apache 和 MySQL 都开启了所以我不明白。

回答by paulsm4

You can access "localhost" just fine.

您可以很好地访问“localhost”。

The "404: file not found" error indicates the server can't find the requested file once you've connectedto localhost.

“404: file not found”错误表示一旦您连接到本地主机,服务器就找不到请求的文件。

ADDENDUM:

附录:

Maybe try to create a regular html file called test.html in one of your vhosts that is not working. Then try to visit that url. That should give you some clue as to what may be the problem. – Gohn67

也许尝试在您的一个不工作的虚拟主机中创建一个名为 test.html 的常规 html 文件。然后尝试访问该网址。这应该会给你一些关于可能是什么问题的线索。– Gohn67

This is good advice. Try it. Specifically:

这是一个很好的建议。尝试一下。具体来说:

1) Create the following five files:

1)创建以下五个文件:

  • C:/xampp/htdocs/dummy-host.localhost/test.html

  • C:/xampp/htdocs/my/test.html

  • C:/xampp/htdocs/launcher/public_html/test.html

  • C:/xampp/htdocs/website/httpdocs/test.html

  • C:/xampp/htdocs/my/test.html

  • C:/xampp/htdocs/dummy-host.localhost/test.html

  • C:/xampp/htdocs/my/test.html

  • C:/xampp/htdocs/launcher/public_html/test.html

  • C:/xampp/htdocs/website/httpdocs/test.html

  • C:/xampp/htdocs/my/test.html

2) Make sure each of these directories exist, and each has a "test.html" with the words "TESTING 1...2...3" in it

2)确保这些目录中的每一个都存在,并且每个目录都有一个带有“TESTING 1...2...3”字样的“test.html”

3) Try each of these five URLs in your browser:

3) 在浏览器中尝试这五个 URL 中的每一个:

4) Report back the exact error you get from each browser URL

4) 报告您从每个浏览器 URL 获得的确切错误

回答by Xfile

Navigate here:

在这里导航:

http://localhost/

If that works, everything is okay.

如果那行得通,一切都会好起来的。

Paste wordpress to xampp/htdocs, and you should not get any error.

将 wordpress 粘贴到xampp/htdocs,您应该不会收到任何错误。

回答by DialDT

I had a similar issue and this is how I resolved it:

我有一个类似的问题,这就是我解决它的方法:

  1. Open the httpd:conf file on the Apache module in XAMPP (click the Congif button)
  2. Scroll through the file - after the first set of comments (#) there is a line of code which says 'Listen 80'. Change this to 81 (or whatever other port you want to use).
  3. Open web browser and explicitly define the port in the web address:

    127.0.0.1:81

  1. 在 XAMPP 中打开 Apache 模块上的 httpd:conf 文件(单击 Congif 按钮)
  2. 滚动文件 - 在第一组注释 (#) 之后,有一行代码显示“听 80”。将其更改为 81(或您想使用的任何其他端口)。
  3. 打开网页浏览器并在网址中明确定义端口:

    127.0.0.1:81

The may or may work for you; I initially had the issue that Apache wouldn't start at all, which is why I changed the port number (couldn't be bothered to figure out which service was using port 80 - if you want to you can use the command netstats -a or netstats -b in command prompt to figure it out)

可能或可能为您工作;我最初遇到的问题是 Apache 根本无法启动,这就是我更改端口号的原因(无法确定哪个服务正在使用端口 80 - 如果您愿意,可以使用命令 netstats -a或 netstats -b 在命令提示符下找出来)

Hope this helps

希望这可以帮助

回答by user3702265

I just encountered this and solve this by creating .htaccess file.

我刚刚遇到了这个问题,并通过创建 .htaccess 文件解决了这个问题。

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /yourfoldername/
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/ [L]
</IfModule>