Skip to content

Instantly share code, notes, and snippets.

@cy-park
Last active April 15, 2021 05:54
Show Gist options
  • Save cy-park/a303e768fb61a2d9fd8d934bcb9c5a0a to your computer and use it in GitHub Desktop.
Save cy-park/a303e768fb61a2d9fd8d934bcb9c5a0a to your computer and use it in GitHub Desktop.
SPA .htaccess rewriting logic
# Prevent viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

# Prevent directory listings
Options All -Indexes

# SPA rewriting logic
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [R=301,L]
</IfModule>

# Prevent access to specific path
# ErrorDocument 401 default
# ErrorDocument 403 default
# <Files admin.php>
# Order deny,allow
# Deny from all
# Allow from 192.168.0.123 localhost
# </Files>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment