Skip to content

Instantly share code, notes, and snippets.

@gustavo-rodrigues-dev
Created February 15, 2013 18:18
Show Gist options
  • Save gustavo-rodrigues-dev/4962250 to your computer and use it in GitHub Desktop.
Save gustavo-rodrigues-dev/4962250 to your computer and use it in GitHub Desktop.
Regra que permite usar um pushState nativo no htacces, onde todas as páginas irão redirecionar para index, além de declarar exceções para as pastas de css, js e imgs
RewriteEngine On
Options +FollowSymLinks
# ----------------------------------------------------------------------
# General Rule
# ----------------------------------------------------------------------
# Redirect all files and paths to index.html
RewriteRule ^index.html(.*)$ - [L,QSA]
# ----------------------------------------------------------------------
# Exception to the general rule
# ----------------------------------------------------------------------
# Declare path and files where don't apply general rules
# js/./../* - not apply general rule redirect of all folders and files to path "/js"
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule js/(.*)$ js/$1 [L,QSA]
# img/./../* - not apply general rule redirect of all folders and files to path "/img"
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule img/(.*)$ img/$1 [L,QSA]
# css/./../* - not apply general rule redirect of all folders and files to path "/css"
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule css/(.*)$ css/$1 [L,QSA]
@faebser
Copy link

faebser commented Jun 11, 2014

i think you can rewrite the exceptions:

# if file exists in the root-dir serve the file with the following rules instead of index.html 
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
# js/./../* -  not apply general rule redirect of all folders and files to path "/js"
RewriteRule js/(.*)$ js/$1 [L,QSA]

# img/./../* -  not apply general rule redirect of all folders and files to path "/img"
RewriteRule img/(.*)$ img/$1 [L,QSA]

# css/./../* -  not apply general rule redirect of all folders and files to path "/css"
RewriteRule css/(.*)$ css/$1 [L,QSA]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment