Laravel works as the root of your site, that is, it is a framework totally oriented to create all applications, from your Dashboard, to multiple sub-domains (see: https://laravel.com/docs/4.2/routing#sub-Domain-routing), example:
Route::group(array('domain' => '{account}.myapp.com'), function()
{
Route::get('user/{id}', function($account, $id)
{
//
});
});
So even if you play your Laravel project in a folder like /etc/www/porta/admin
or /public_html/portal/admin
it will not recognize when accessing:
'Cause Laravel’s gonna search the routes for this /portal/admin
and not this /admin
, so the idea of Laravel is that you design with it all pages, to take advantage of all Views and Models and also make the application scalable, thus avoiding creating different things for the same task. Note that just because you used Laravel to create the entire application does not mean you will be able to make it scalable without having the knowledge and experience with this kind of thing (however this is off topic here)
Fortunately it is possible to bypass Laravel’s routes and make it accessible, edit the file app/Http/routes.php
and edit routes by adding a prefix /portal/admin
, so where do you use:
Route::get('/', ...
Will stay:
Route::get('/portal/admin', ...
An example:
$prefixo = '/portal/admin';
//http://site/portal/admin
Route::get($prefixo, function () {
return view('login');
});
//http://site/portal/admin/dashboard
Route::get($prefixo . '/dashboard', function () {
//...
});
//http://site/portal/admin/logout
Route::get($prefixo . '/logout', function () {
//...
});
If the address changes, you will have to change all prefixes /portal/admin
. I don’t know Laravel at all, maybe with group
it is possible to do this more easily.
Note one very important thing, the folder admin
must have the content of public
, so the other folders of the Laravel will be out of admin
, but if this is not possible, you can put everything inside admin
, even the public and create a . htaccess to redirect, as in these responses:
It should stay that way in your case:
./public_html (Pasta root da hospedagem)
|--- portal
|--- admin
|--- .htaccess (arquivo .htaccess que você deve criar)
|--- /public
|--- index.php
|--- .htaccess
|--- /app
|--- /bootstrap
|--- /config
|--- /database
The . htaccess file should look like this:
RewriteEngine On
RewriteRule ^ /public/index.php [L]
When to access http://www.site/portal/admin/
this will make a total redirect to the file /public_html/portal/admin/public/index.php
.
All this comes to be a gambiarra, aiming that the Laravel was designed to work as root and there may be some difficulties in using this way, as other possible incompatibilities, what I recommend is to start thinking about maybe redoing the project (as far as possible).
Every time I go to a hosting I put all the files inside the folder I want. Let’s assume it’s admin. After that just access the LINK and put the /public in the end. www.meusite.com.br/portal/admin/public
– Diego Souza
Related or duplicated: http://answall.com/questions/43685/problema-com-subpastas-e-reescrita-de-url-laravel
– Wallace Maxters