我已经通过网络搜索解决了我的问题,但没有解决方案适合我,所以经过几个小时的路由模块挣扎后,我决定请你帮忙。
问题
我无法从 / public 目录之外访问Laravel应用程序。我需要在浏览器中键入 localhost \ projects \ laravel \ public ,但我想要的是使用 / public 的URL。主要原因是因为我使用共享主机并且无法访问apache配置文件,所以我无法创建vhost。
背景
我已经在:** c:\ xampp \ htdocs \ projects \ laravel **下手动安装了Laravel框架,并使用composer为我完成剩下的工作。
路由设置为: Route :: get('/','HomeController @ showWelcome');
在我的项目根目录中** c:\ xampp \ htdocs \ projects \ laravel **我放了一个.htacces文件,其中包含以下内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projects/laravel/
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
在我的应用程序根目录 c:\ xampp \ htdocs \ projects \ laravel \ public 我有.htaccess,其中包含以下代码:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
当我输入:localhost \ projects \ laravel \我有NotFoundHttpException
当我输入:localhost \ projects \ laravel \ public我有欢迎页面
任何帮助都会很感激,谢谢。
答案 0 :(得分:2)
最后,我有这个工作。有两种解决方案可以做。
@Wasim已经在这个帖子中发布了第一个对我有用但我不想实现的内容:Laravel 4 removing public from URL由于内容核心结构位于同一目录中,因此解决方案不会保存。申请本身。这可能会在将来的实施中引起一些问题。
您需要将所有内容从 public / 文件夹中升级到项目 ROOT 目录,然后替换 index.php中的内部路径文件正确的一个。出于安全原因,此.htaccess文件需要放入项目ROOT目录
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
上面描述的修改后的Laravel结构可以上传到您的共享虚拟主机,应用程序应该在我们的http地址中与/ public一起运行。
此解决方案不要求您将/ public文件夹的内容移动一级,但要求您拥有对共享主机中 ../ ROOT 目录的读写权限(../ROOT目录主要包含 public_html , public_ftp 和其他文件夹)。
您需要将Laravel结构移动到 ../ ROOT 目录中,如下所示:
app/
bootstrap/
vendors/
public_html/
public_ftp/
(...)
文件格式 / public 文件夹转到 public_html
public_html/index.php
public_hmtl/.htaccess
public_html/packages/
(...)
然后需要修改/bootstrap/paths.php以使用&#39; public&#39;键:
&#39;公共&#39; =&GT;的 DIR 强>&#39; /../公共&#39;公共&#39; =&GT;的 DIR 强>&#39; /../的的public_html 强>&#39;
如果有人遇到类似问题且此解决方案无效,请通知我,谢谢。
答案 1 :(得分:0)
如果你想在uri上没有公开,请使用你的laravel root中的composer。使用命令php artisan serve并从浏览器浏览localhost:8000。它会带你到主页。
答案 2 :(得分:0)
你从哪里得到这条线?
RewriteRule ^(.*)$ public/$1 [L]
这不是Laravel的一部分。尝试删除它或Laravel根目录中的整个.htaccess文件。