I have the following directory structure:
/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)
I am trying to use an apache RewriteRule to redirect a request to http://example.com/~user/my_laravel_app
to http://example.com/~user/my_laravel_app/public/index.php
. In the first .htaccess
file (the one directly under the my_laravel_app/
directory, I have the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~username/my_laravel_app
RewriteCond %{THE_REQUEST} !public/
RewriteRule ^(.*)$ public/index.php [R]
</IfModule>
When I navigate my browser to http://example.com/~username/my_laravel_app
, I correctly get redirected to http://example.com/~user/my_laravel_app/public/index.php
, and the laravel application loads as expected displaying the route for /
as defined in app/routes.php
.
However, I want the redirect to be internal, meaning, I don't want the users browser to display the new location. So, I simply remove the [R]
flag on the rule. The .htaccess
file now contains:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~username/my_laravel_app
RewriteCond %{THE_REQUEST} !public/
RewriteRule ^(.*)$ public/index.php
</IfModule>
Now, when I direct the browser to http://example.com/~username/my_laravel_app
I get a Laravel whoops error page saying there was a NotFoundHttpException
. When I look at the error page, it seems as though the redirect is "working", because I see that the SCRIPT_NAME
is /~username/my_laravel_app/public/index.php
.
However, I believe the issue is possibly that the REQUEST_URI
is /~username/my_laravel_app/
, instead of '/', as it would be if Laravel were installed in the root of a domain like normal. So it seems as though Laravel is looking for a route match using this REQUEST_URI
variable.
Is there any way to get Laravel to recognize the correct route?