Access Laravel Site Without “Public” Folder Using Alias in AWS EC2

Recently, I had an issue with laravel project settings, especially to get rid of public and index.php from url to access the site. For example,, or,, etc.

I came through some solutions from StackOverflow or whatever, and they suggested me to use .htaccess, apache rewrite, or aliasing, etc. Some gave good solution, and some others not. Although they somehow worked, I felt a bit tempting to know the best practices, especially to prevent  attacher/hacker.

So overall, I received two recommendations: using .htaccess or aliasing in apache configurations (please let me know if anyone of you know any better options, that would be much appreciated). However, I will only put my solution here.

  1. Edit apache configuration
    1. find the configuration in /etc/httpd/conf/httpd.conf, and add lines below:
      • Alias /my_laravel "/var/www/html/laravel_project/public"

        <Directory “/var/www/html/laravel_project/public”>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        Allow from all

    2. restart apache: sudo httpd service restart
  2. Edit .htaccess in public folder, add lines below:<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
    Options -MultiViews
    </IfModule>RewriteEngine On

    RewriteBase /my_laravel

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

  3. Done, now we can directly use, and call any controller with, without public or index.php

Basically, in step 1, we let apache to directly jump to public folder, so it will prevent any access to the upper level. While in step 2, there should be rewrite base to let the redirection works, and add rewrite rule to remove index.php.

I hope this also helps any of you who read this article. Please let me know if you have better alternatives 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s