如何在Laravel 4.2中将基本URL设置为/subfolder [英] How to set base url to /subfolder in Laravel 4.2

查看:74
本文介绍了如何在Laravel 4.2中将基本URL设置为/subfolder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照www.example.com/bangla 这样的共享主机的/subfolder /16683938/3975838>此答案.

I have uploaded my laravel 4.2 application to a /subfolder of a shared hosting like www.example.com/bangla by following this answer.

我的应用程序的结构是

example.com/    (the root of your web hosting)
|-- laravel4_base/   (Here goes all contents except public folder)
|-- [some other folders...]
|-- public_html/    
|   |-- [some other folders...]
|   |-- bangla/      (Here goes contents of public folder)

现在我的视图中有这些菜单链接

Now i have these menu link in my view

<li><a href="/">Home</a></li>
<li><a href="/rj">Rj</a></li>

我的问题是,每当我单击它们时,都应该将我路由到

My problem is whenever i click them should route me to

www.example.com/bangla
www.example.com/bangla/rj

但是需要

www.example.com
www.example.com/rj

我的 route.php 看上去

Route::get('/','HomeController@index');
Route::get('rj','HomeController@rj');

HomeController.php 外观

public function index()
{
    return View::make('home');
}
public function rj()
{
    return View::make('rj');
}

因此,基本上基本路径不会更改为子文件夹 www.example.com/bangla

So basically the base path is not being changed to subfolder www.example.com/bangla

我在stackoverflow中做了很多搜索.有些是

I did a lot of searching in stackoverflow. Some are

laravel 4将基本URL设置为/subfolder

如何设置基本URL的子目录laravel?

也在 laracast 中.但是所有人都没有答案,或者他们没有任何解决问题的答案.

Also in laracast. But all are either unanswered or they do not have any answer that resolves the problem.

因此,简单来说,问题是如何将基本网址从 www.example.com 更改为 www.example.com/bangla

So, in simple words the question is how to change base url from www.example.com to www.example.com/bangla

推荐答案

如果您使用以/开头的URL,它将告诉浏览器这是一个绝对URL,因此浏览器自然会从根目录开始查找它.当前URL的名称,该URL始终是域.

If you use a URL that starts with / it will tell the browser that it is an absolute URL so the browser will natually start looking for it from root of your current URL, which is always the domain.

为防止这种情况,您可以使用laravel的帮助器函数为您生成URL.

To prevent this, you can use laravel's helper functions to generate the URL for you.

http://laravel.com/docs/4.2/helpers#urls

<li><a href="{{ action('HomeController@index') }}">Home</a></li>
<li><a href="{{ action('HomeController@rj') }}">Rj</a></li>

这篇关于如何在Laravel 4.2中将基本URL设置为/subfolder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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