【问题标题】:How to redirect to public folder on laravel如何重定向到laravel上的公共文件夹
【发布时间】:2015-07-01 23:59:19
【问题描述】:

我有这个结构:

我的域名:www.example.com

这是我 laravel 的项目文件夹:http://www.example.com/project

我想重定向到http://www.example.com/project/public

我知道这个答案之前已经回答过,但我尝试实施它但对我不起作用。

对不起我的英语,我只会说西班牙语

【问题讨论】:

  • 你使用的是 nginx 还是 apache?

标签: .htaccess redirect laravel directory public


【解决方案1】:

对于htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{REQUEST_URI} !project/public/
RewriteRule (.*) /project/public/$1 [L]

将其放入您的 public_html/ 或 www/ 文件夹中,其中 example.com/ 的根目录

【讨论】:

  • 不知何故这不适用于 localhost 作为 URL。 (第三行是我认为的问题,不知道为什么)
  • 正如@BenFransen 上面所说,这在本地主机中对我不起作用。刚刚更改为 dev linux 机器主机名,现在可以正常工作了。
【解决方案2】:

将 /server.php 重命名为 index.php

【讨论】:

  • 这可行,但您必须编辑 CSS 和 JS 文件的所有路径。不如 .htaccess 解决方案实用。
【解决方案3】:

我创建了这个php脚本,放在laravel目录的根目录下:

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; header("位置:" . $actual_link . "public/index.php");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-24
    • 2019-10-16
    • 2019-01-27
    • 2018-05-03
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    相关资源
    最近更新 更多