How to make apache serve file:///

I'm kind of new to HTML, PHP and stuff.

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

"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/). 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

"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.

If I instead type in

"localhost/index.html"

and then click on the link, the browser calls

"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? 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:/// . 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).


No. The file:/// protocol is not HTTP. The browser won't even send it to the localhost server you're running, and instead just read the file.

链接地址: http://www.djcxy.com/p/41294.html

上一篇: 相对链接(来自https)给出了301永久移动(到http)

下一篇: 如何制作apache服务文件:///