问题
I have uploaded my laravel 4.2 application to a /subfolder
of a shared hosting like www.example.com/bangla by following this answer.
Structure of my application is
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
But it takes to
www.example.com
www.example.com/rj
My route.php looks like
Route::get('/','HomeController@index');
Route::get('rj','HomeController@rj');
HomeController.php looks like
public function index()
{
return View::make('home');
}
public function rj()
{
return View::make('rj');
}
So basically the base path is not being changed to subfolder www.example.com/bangla
I did a lot of searching in stackoverflow. Some are
laravel 4 setting base url to /subfolder
How to set sub-directory for base URL of laravel?
Also in laracast. But all are either unanswered or they do not have any answer that resolves the problem.
So, in simple words the question is how to change base url from www.example.com to www.example.com/bangla
回答1:
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.
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>
回答2:
I met this problem too and m'm code like this
<a class='btn btn-warning' href='{{ url('/jobCatEdit/'.$dtJobCat->jcid) }}'>
and it's work
来源:https://stackoverflow.com/questions/33127507/how-to-set-base-url-to-subfolder-in-laravel-4-2