4
I’m trying to do the Laravel 4
run in a subdirectory, using . htaccess to rewrite the url to the public folder
Example:
C:\xammp\htdocs\laravel4
- The
.htaccess
is in rewritingC:\xammp\htdocs\laravel4
forC:\xammp\htdocs\laravel4\public
Works properly for the rewrite. However, when I try the file routes.php
create a configuration, always returns page not found.
Example:
If I access localhost/laravel4/teste
, with the configuration below, Laravel says that the page was not found.
Route::get('/teste', function(){
return "Hello World";
});
Now, when I do it this way below, it shows correctly:
Route::get('laravel4/teste', function(){
return "Hello Word";
});
Between tests and others, I discovered that Laravel 4, when going to hoard the url, does not use the $_SERVER['PATH_INFO']
(which would return only the parameters after the public/index.php rewritten), but the $_SERVER['REQUEST_URI']
(that would return everything that comes after the http://localhost/
).
So I can rewrite the url, but I can’t configure the routes normally, but only when I use a prefix referring to the subfolder I’m using.
How to solve this problem without having to change Laravel 4 core?
Is there any way to ignore or prefix these routes internally (Some method in the Route class or some global configuration) ?
Try with
teste
instead of/teste
.– Rodrigo Rigotti
@Rodrigorigotti, I did this, but the result was the same (only works with the unwanted prefix). Looks like, internally, Laravel4 already handles those bars.
– Wallace Maxters
I don’t think it’s a good idea to expose your entire application in an internet-free folder. You can make a vhost pointing directly to the public folder of the Laravel, besides safer will not have other problems
– gmsantos
@gmsantos, I also thought about this possibility, but, in local development, it is good to adapt the application to what it will be in production; and, in production, on a shared server, no one has access to a vhost.
– Wallace Maxters