简体   繁体   English

如何使Apache服务file:///

[英]How to make apache serve file:///

I'm kind of new to HTML, PHP and stuff. 我对HTML,PHP和其他东西有点陌生。

I'm trying to test locally a web site before putting it online. 我正在尝试在网站上线之前对其进行本地测试。 I set up my Apache server with PHP and MySQL and made a virtual server point localhost to 我使用PHP和MySQL设置了Apache服务器,并将虚拟服务器指向localhost

"C:/path/to/docroot/"

and everything works great. 一切都很好。

Now in my index.html I have a link pointing to the file "mail-form.php" in the same directory (the C:/path/to/docroot/). 现在在我的index.html中,我有一个指向同一目录(C:/ path / to / docroot /)中的文件“ mail-form.php”的链接。 In this link I only specified 在此链接中,我仅指定

href="mail-form.php"

and no absolute path, because I don't know which would be the absolute path in the production server and I don't feel like changing them all after testing. 而且没有绝对路径,因为我不知道生产服务器中的绝对路径是什么,并且我不想在测试后全部更改它们。 (Here I'm open for suggestions, if this is bad). (如果情况不好,我愿意征求您的意见)。

Now the thing I don't understand is the following: when I type in the browser's URL 现在我不明白的是:当我输入浏览器的URL时

"file:///C:/path/to/docroot/index.html"

and then click on the link, the browser tries to open 然后单击链接,浏览器尝试打开

"file:///C:/path/to/docroot/mail-form.php"

and this doesn't get interpreted by PHP, but returned as text. 而这并没有被PHP解释,而是以文本形式返回。

If I instead type in 如果我输入

"localhost/index.html"

and then click on the link, the browser calls 然后点击链接,浏览器会调用

"localhost/mail-form.php" “ localhost / mail-form.php”

and it gets interpreted properly showing what it should. 并正确解释了它应该显示的内容。

I can obviously live with this, but I'm curious if there is a way to make Apache/PHP serve the "file:///..." thing just as well as the "localhost/..." thing? 我显然可以接受这一点,但是我很好奇是否有一种方法可以使Apache / PHP和“ localhost / ...”一样服务“ file:/// ...”吗? After all they are both the same file. 毕竟它们都是同一个文件。 Or is it a browser problem? 还是浏览器问题? Or am I thinking wrong? 还是我想错了?

You can't make Apache serve file:/// . 您不能使Apache服务file:/// Using that scheme instructs the browser to fetch the file directly from the filesystem. 使用该方案可指示浏览器直接从文件系统中获取文件。 If you want to use Apache then you have to use http:// (or another URL scheme that makes a network request that Apache supports). 如果要使用Apache,则必须使用http:// (或发出Apache支持的网络请求的其他URL方案)。

No. The file:/// protocol is not HTTP. file:///协议不是HTTP。 The browser won't even send it to the localhost server you're running, and instead just read the file. 浏览器甚至不会将其发送到您正在运行的localhost服务器,而是只读取文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM