【问题标题】:PHP-Laravel redirect to root(/) from /index.phpPHP-Laravel 从 /index.php 重定向到 root(/)
【发布时间】:2021-09-21 12:16:46
【问题描述】:

我正在开发一个 larvel 项目,当我输入没有 /index.php 的 url(域)时,一切都很好。假设我的网址是https://example.com。当我访问此网址时,一切正常。但是如果我在最后添加/index.php 就像https://example.com/index.php 一样,我的资源(图像、视频)由于路径不匹配而无法加载。到目前为止,我发现我需要通过在 .htaccess 文件上定义规则来将 https://example.com/index.php 重定向到 https://example.com

那么如何正确编写规则,以便在我输入 https://example.com/index.php 时重定向到 https://example.com

更新:在开发中,我的项目在 http://localhost:3000/Example 上运行。在这种情况下,我需要将此http://localhost:3000/Example/index.php 重定向到http://localhost:3000/Example

【问题讨论】:

标签: php laravel php-7


【解决方案1】:
    RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=301,NC,NE]

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=301,NC,NE]

打开 RewriteEngine 并在 RewriteEngine On 下面添加上面的行

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-06-22
  • 2021-01-26
  • 1970-01-01
  • 2018-05-27
  • 2012-11-22
  • 1970-01-01
  • 1970-01-01
  • 2013-05-18
相关资源
最近更新 更多