0

I'm using Laravel for my website, but i'm encountering a problem.

My website does not have any public_html or htdocs folder, but the root itself it is already public. Because of this i'm obliged to put all the Laravel files to the root folder.

To who doesn't know, when using Laravel the public folder is generally the subfolder public, therefore right now if I want to access my Laravel web applicaton I have to navigate to http://www.mywebsite.com/public.

I need to edit the .htaccess in order to show from http://www.mywebsite.com/ the subfolder public files and deny any access to the root files.

So http://www.mywebsite.com/public/index.php should be http://www.mywebsite.com/index.php, http://www.mywebsite.com/public/images/logo.png should be http://www.mywebsite.com/images/logo.png and so on.

Now I'm wondering, is it even possible?

Laravel .htaccess original file is:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

1 Answer 1

0

I've been successful to solve this myself by editing the original .htaccess to:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond public/%{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ public/$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond public/%{REQUEST_FILENAME} !-d
    RewriteCond public/%{REQUEST_FILENAME} !-f
    RewriteRule ^ public/index.php [L]
</IfModule>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.