douyaju4259 2016-04-13 09:27
浏览 62
已采纳

WAMP:Index.php在选择目录时立即执行/运行

I had a little, slightly annoying problem that was an easy fix but I didn't understand why it took place.

I have a several folders in ../wamp/www/- and in one of them I had a file, that I had created, named index.php. When I clicked on the other directories I could browse through the normal list where I saw all the files, but when I opened the folder where the file Index.php was it executed immediately and I never saw what was in the folder. Instead I had to manually change the url to open other files in that directory.

I deleted index.php and half expected it to run some other .php-file in that directory, but didn't.

I'm aware of that there is a index.php-file in the www-directory (the comments in French though), which clearly is part of the WAMP system I downloaded, but having seen tutorials where people use index.php I'd have expected someone to mention this potential problem.

  • 写回答

1条回答 默认 最新

  • dongping5230 2016-04-13 14:24
    关注

    This is not a problem!

    This is how web servers work.

    To be specific there is a setting in the Apache config that tells Apache the names of files that it should run Automatically if no actual file is specified in the URL

    Specifically this line in httpd.conf

    DirectoryIndex index.php index.php3 index.html index.htm
    

    It is normal that a web server will run any of these files if it sees them when only the directory is specified on a URL.

    And before you consider changing it, dont. Almost everything you will come accross EXPECTS this to be the case.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?