Laravel 5 – 从 URL 中删除公共 [英] Laravel 5 – Remove Public from URL

查看:25
本文介绍了Laravel 5 – 从 URL 中删除公共的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个非常受欢迎的问题,但我一直没能找到适用于 Laravel 5 的解决方案.我一直试图从 Codeigniter 迁移很长时间,但这个复杂的安装过程让我很不爽.

I know this is a very popular question but I haven't been able to find a working solution for Laravel 5. I've been trying to migrate from Codeigniter for a long time, but this convoluted installation process keeps putting me off.

我不想运行虚拟机,这在项目之间切换时似乎很尴尬.

I don't want to run a VM, this just seems awkward when switching between projects.

我不想将我的文档根目录设置为公共文件夹,这在项目之间切换时也很尴尬.

I don't want to set my document root to the public folder, this is also awkward when switching between projects.

我已经尝试过 .htaccess mod_rewrite 方法

I've tried the .htaccess mod_rewrite method

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

这只是在compiled.php 行7610 中给了我一个Laravel NotFoundHttpException.

This just gives me a Laravel NotFoundHttpException in compiled.php line 7610.

前阵子试L4的时候,用的是把public文件夹的内容移到root的方法.L5 的结构完全不同,按照相同的步骤完全破坏 Laravel(服务器只会返回一个空白页面).

When I tried L4 a while ago, I used the method of moving the contents of the public folder into the root. The structure of L5 is quite different and following the same steps completely broke Laravel (the server would only return a blank page).

是否有一种像样的方法可以在开发环境中删除public":

Is there a decent method of removing 'public' in a development environment that:

  1. 适用于 L5
  2. 让我可以轻松地在项目之间切换(我通常同时处理 2 个或 3 个).

谢谢

** 我使用的是 MAMP 和 PHP 5.6.2

** I'm using MAMP and PHP 5.6.2

推荐答案

对于 Laravel 5:

  1. 将 Laravel 根文件夹中的 server.php 重命名为 index.php
  2. .htaccess 文件从 /public 目录复制到你的 Laravel 根目录文件夹.
  1. Rename server.php in your Laravel root folder to index.php
  2. Copy the .htaccess file from /public directory to your Laravel root folder.

就是这样!

这篇关于Laravel 5 – 从 URL 中删除公共的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆