php - 如何在子目录 Laravel 中正确配置 htaccess?
问题描述
我目前正在遵循本指南,以允许在 Laravel 中运行我们当前的遗留 PHP 应用程序,以便随着时间的推移完全迁移。 https://tighten.co/blog/converting-a-legacy-app-to-laravel/
为此,我设法让 Laravel 运行遗留应用程序 index.php 文件,但是我相信路由可能存在一些问题,因为 URL 不正确并且登录页面未加载。
这是我当前的文件结构,我有两个 .htaccess 文件,一个位于 laravel 的根目录,一个位于 legacy 文件夹的根目录。
laravel 根 htaccess 文件正在重写公用文件夹,因此在开发时它不应该显示在 URL 中。
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]
遗留应用程序 .htaccess 文件处理旧系统的视图和文件的所有路由,见下文。
Options -Indexes
DirectoryIndex index.php
AddType image/svg+xml svg
AddType image/svg+xml svgz
# HSTS Header - removed https only as AWS lb > server is http
Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
# core redirects
RewriteEngine On
RewriteBase /legacy
RewriteRule ^login/?$ /views/login/index.php [QSA,L]
RewriteRule ^app-redirect?$ /callback/apps/redirect_device.php [QSA,L]
RewriteRule ^login/logout?$ /views/login/logout.php [QSA,L]
RewriteRule ^register([/]*)$ /views/login/register.php [QSA,L]
RewriteRule ^login/change-password([/]*)$ /views/login/change_password.php [QSA,L]
RewriteRule ^authenticate/auth-check([/]*)$ /views/login/auth_check.php [QSA,L]
访问应用程序时,它似乎也影响了公共 URL 重写,因为它将公共重新添加到 URL 中,如下所示:
system.co.uk/public/login
什么时候应该
system.co.uk/login
摘要:
所以我让它成功运行了位于遗留文件夹中的 index.php 文件,但是它只是停在那里它似乎没有将遗留 .htaccess 文件中的任何路由(如 /login)带入帐户。
有谁知道这里会发生什么?
解决方案
旧文件夹下的 htaccess 文件不应影响根文件夹。重定向可以被您的浏览器缓存,您是否尝试过其他浏览器或使用隐身模式?
推荐阅读
- python - 试图减去列表元素的百分比
- python - 在python中使用dill从文件夹加载多个文件?
- reactjs - Reactjs:在功能组件中实现危险的SetInnerHTML
- php - Twig 在页面上发布空模块
- laravel - Laravel 邮件发送给自己
- python - groupby 方法调用的区别?
- jquery - 工具栏中的下拉列表在 kendo MVC 中显示为文本框
- amazon-web-services - Amazon Data Lifecycle Manager:“没有附加 EBS 支持的卷”错误
- sql - SQL Server:从自定义表定义列表中进行列合并
- c - 谁能解释一下这个 C 代码的工作原理?