php - Apache - 使用 .htaccess 重定向到根文件夹
问题描述
我的.htaccess文件有问题。我以这种方式配置它。
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/$ index.php?controller=$1 [L]
每次我http://localhost/mvc3/contacto/
访问 http://localhost/mvc3/index.php?controller=contacto
时,它都是正确的,但是如果友好的 URL 我删除了最后一个字符/
(http://localhost/mvc3/contacto),它会将我返回到根页面(wampserver 服务器)。
这是问题的视频中的解释,会发生什么?
解决方案
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?controller=$1 [L]
从重写规则中删除斜线,它应该可以工作。
推荐阅读
- excel - 使用名称中带有“/”的 VBA 保存 excel 工作簿
- php - PHP用锚标记替换字符串中的URL
- c# - 无法检查 WinAppDriver 中的 Grids/StackPanels/Custom Controls 并通过 Appium 的 AccessibilityId 找到它们
- flutter - 具有标记人员功能的 Flutter TextField
- swift5 - 当我单击 UISearchController Swift 5 时,我的应用程序停止运行
- go - 用于服务间通信的基于 gRPC 的微服务架构
- javascript - 将函数 prop 传递给子组件(通过 Link 和 Route 组件)
- xamarin.forms - 如何在 Xamarin iOS 和 Android 在管道中构建任务之前替换 json 配置值
- python - 将二维向量多次添加到另一个二维向量的有效方法
- angular - 已选择 Angular 自动完成输入并模糊事件竞争条件