Skip to content

Instantly share code, notes, and snippets.

@labibmuhajir
Last active October 16, 2025 03:51
Show Gist options
  • Select an option

  • Save labibmuhajir/3c6d83865209d324d61db761e84fa0bc to your computer and use it in GitHub Desktop.

Select an option

Save labibmuhajir/3c6d83865209d324d61db761e84fa0bc to your computer and use it in GitHub Desktop.
2 htaccess php cpanel with laravel 12 sample
# htdocs/
# ├─ public/
# │ └─.htaccess //second file
# │
# ├─ src/
# └─.htaccess //first file
# first .htaccess in root host folder
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=302]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
# second .htaccess in public folder
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
### sample second .htaccess in public folder full version laravel 12
<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}]
# Handle X-XSRF-Token Header
RewriteCond %{HTTP:x-xsrf-token} .
RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment