更改PHP接收的URL(throug.htaccess?)



我通过从laracasts.com构建一个项目来学习PHP。我正在运行一个XAMPP堆栈。

在该项目中,我正在读取浏览器通过读取$_SERVER['REQUEST_URI']发送给我的URL。当我在浏览器中键入时

http://localhost/php-learning/

我收到

php学习/

这正是我所期望的。但当我在浏览器中键入时

http://localhost/php-learning/contact

我得到一个错误404:找不到对象。仅当我键入时

http://localhost/php-learning/index.php/contact

我收到

php学习/index.php/contact

有人能给我推荐一个可以了解这里发生了什么的地方吗?我怎样才能去掉url中的index.php?

也许对你们中的许多人来说,这是一个非常基本的问题,但我正在学习;-(

问候,

Hubert

关于调整vhosts:

I can only find a file httpd-vhosts.conf which contains
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "${SRVROOT}/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error.log"
CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "${SRVROOT}/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

验证你的Nginx/Apache vhosts配置,在那里你会发现一个规则,它会声明包含"index.php";对于/path。只要在index.php之前添加一个斜线,它就会看起来像/index.php。问题是,如果你不在index.php之前添加/,它会试图在你的子目录路径中找到一个单独的index.php。因此,如果在它之前添加/,那么它将始终使用根index.php文件。