<IfModule mod_rewrite.c>
    RewriteEngine On

    # Live — https://meatworx.in/
    RewriteCond %{HTTP_HOST} ^(www\.)?meatworx\.in$ [NC]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://meatworx.in%{REQUEST_URI} [R=301,L]

    RewriteCond %{HTTP_HOST} ^www\.meatworx\.in$ [NC]
    RewriteRule ^ https://meatworx.in%{REQUEST_URI} [R=301,L]

    # Keep /public out of the address bar.
    RewriteCond %{HTTP_HOST} ^(www\.)?meatworx\.in$ [NC]
    RewriteCond %{THE_REQUEST} \s/+public(?:/|\s|\?) [NC]
    RewriteRule ^public/?(.*)$ https://meatworx.in/$1 [R=301,L,NE]

    # Library images: storage/app/public, even when public/storage is not linked.
    RewriteCond %{HTTP_HOST} ^(www\.)?meatworx\.in$ [NC]
    RewriteCond %{REQUEST_URI} !\.\.
    RewriteCond %{DOCUMENT_ROOT}/storage/app/public/$1 -f
    RewriteRule ^storage/(.*)$ storage/app/public/$1 [END]

    # Files that live in public/ (css, images, storage).
    RewriteCond %{HTTP_HOST} ^(www\.)?meatworx\.in$ [NC]
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
    RewriteRule ^(.*)$ public/$1 [L]

    # Everything else goes through Laravel.
    RewriteCond %{HTTP_HOST} ^(www\.)?meatworx\.in$ [NC]
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^ public/index.php [L]

    # Local — http://localhost/ambikesh/meatworx/web
    RewriteCond %{HTTP_HOST} localhost [NC]
    RewriteCond %{THE_REQUEST} \s/+ambikesh/meatworx/web/public(?:/|\s|\?) [NC]
    RewriteRule ^public/?(.*)$ /ambikesh/meatworx/web/$1 [R=301,L,NE]

    RewriteCond %{HTTP_HOST} localhost [NC]
    RewriteCond %{REQUEST_URI} !\.\.
    RewriteCond %{DOCUMENT_ROOT}/ambikesh/meatworx/web/storage/app/public/$1 -f
    RewriteRule ^storage/(.*)$ storage/app/public/$1 [END]

    RewriteCond %{HTTP_HOST} localhost [NC]
    RewriteCond %{REQUEST_URI} !/web/public/
    RewriteCond %{DOCUMENT_ROOT}/ambikesh/meatworx/web/public/$1 -f
    RewriteRule ^(.*)$ public/$1 [L]

    RewriteCond %{HTTP_HOST} localhost [NC]
    RewriteCond %{REQUEST_URI} !/web/public/
    RewriteRule ^ public/index.php [L]
</IfModule>
