首页 > 解决方案 > 只需在 url 中写入 /mvc/ 并删除 .php 即可访问 /mvc/public/index.php

问题描述

我正在学习 mvc 概念,我发现了一个视频,其中他做了一些更改,但是当我编写与他编写的相同代码时,这些更改并未应用。我的意思是没有写 php 但他在 .htaccess 文件中做了一些更改

我的问题是,我的文档根目录是c/xampp/htdocs/mvc/public/index.php,当我编写时localhost/mvc,里面的所有文件和文件夹都出现在 mvc 中,我不希望这样。我希望将其直接重定向到mvc/public/index.php页面,并且扩展名 .php 不应出现在 url

我在索引文件中的代码

echo "request url " . $_SERVER['REQUEST_URI'];

并且该.htaccess文件位于公共文件夹中并且是

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule ^(.*)$ index.php?$1 [L,QSA]

标签: phpapachemodel-view-controllerconfig

解决方案


推荐阅读