【发布时间】:2015-07-20 05:22:53
【问题描述】:
我的目录结构如下:
/home/username/public_html
my_laravel_app/
.htaccess
app/
bootstrap/
public/
.htaccess
index.php
robots.txt
...etc (standard Laravel 4 public folder contents)
vendor/
...etc (standard Laravel 4 files and folders)
我正在尝试使用 apache RewriteRule 将请求重定向到 http://example.com/~user/my_laravel_app 到 http://example.com/~user/my_laravel_app/public/index.php。在第一个.htaccess文件中(my_laravel_app/目录下的那个,我有如下代码:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~username/my_laravel_app
RewriteCond %{THE_REQUEST} !public/
RewriteRule ^(.*)$ public/index.php [R]
</IfModule>
当我将浏览器导航到http://example.com/~username/my_laravel_app 时,我正确地被重定向到http://example.com/~user/my_laravel_app/public/index.php,并且laravel 应用程序按预期加载,显示/ 的路由,如app/routes.php 中定义的那样。
但是,我希望重定向是内部的,也就是说,我不希望用户浏览器显示新位置。所以,我只是删除了规则上的[R] 标志。 .htaccess 文件现在包含:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~username/my_laravel_app
RewriteCond %{THE_REQUEST} !public/
RewriteRule ^(.*)$ public/index.php
</IfModule>
现在,当我将浏览器定向到 http://example.com/~username/my_laravel_app 时,我得到一个 Laravel 糟糕的错误页面,说有一个 NotFoundHttpException。当我查看错误页面时,似乎重定向正在“工作”,因为我看到SCRIPT_NAME 是/~username/my_laravel_app/public/index.php。
但是,我认为问题可能是 REQUEST_URI 是 /~username/my_laravel_app/,而不是“/”,就像 Laravel 像正常一样安装在域的根目录中一样。所以看起来 Laravel 正在使用这个 REQUEST_URI 变量寻找路由匹配。
有没有办法让 Laravel 识别正确的路线?
【问题讨论】:
标签: php apache .htaccess laravel mod-rewrite