Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
@guilhermemuller

This comment has been minimized.

Copy link

commented Apr 26, 2018

It worked for me, thank you very much.

@mrhili

This comment has been minimized.

Copy link

commented Aug 26, 2018

Worked for me to thank you

@HeroGuys

This comment has been minimized.

Copy link

commented Sep 5, 2018

My laravel does not see css, js, etc files and routes
Access file in / public

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

    RewriteEngine On
    
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

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

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

Access file in / root folder laravel project

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ ^$1 [N]

    RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
    RewriteRule ^(.*)$ public/$1 

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ server.php

</IfModule>
@BassemN

This comment has been minimized.

Copy link

commented Sep 21, 2018

Thanks allot 👍

@BassemN

This comment has been minimized.

Copy link

commented Sep 21, 2018

@liaotzukai Could you explain what each rule do, please?

@Akki-8388

This comment has been minimized.

Copy link

commented Feb 12, 2019

Its working thank you,it saved my time @HeroGuys

@sibche2013

This comment has been minimized.

Copy link

commented Mar 26, 2019

hello
@liaotzukai this code works very well , but when we can access site with site.com and site.com/public ! how can we disable view in public folder? i want only user can view site from site.com URL not site.com and site.com/public

@nandalal

This comment has been minimized.

Copy link

commented Jun 30, 2019

Hello
@liaotzukai everything is working fine, when i past the url with /public also able to access the normal way. is it any issues, and i need to block the .env file, so i added one more line to the above .htaccess. on the bottom line of " RewriteRule ^ server.php ". i added " RewriteRule ^.env - [F,L,NC] ".
Can you tell me the solution for block the link if we put additional uri called /public to the normal url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.