Skip to content

Instantly share code, notes, and snippets.

@dkrusky
Created January 9, 2017 10:46
Show Gist options
  • Save dkrusky/b6697ab582520c2c6b8c57967b58a459 to your computer and use it in GitHub Desktop.
Save dkrusky/b6697ab582520c2c6b8c57967b58a459 to your computer and use it in GitHub Desktop.
handle modern favicons, app path exclusion, seo files, ignore images scripts and fonts, redirect all to page handler and if file not found send different query string to page handler.
RewriteEngine On
# handle modern favicons
RewriteRule ^(browserconfig.xml|manifest.json|safari-pinned-tab.svg|(android-chrome|favicon|mstile)-[0-9]+x[0-9]+.png|apple-touch-icon(-precompressed.png|-[0-9]+x[0-9]+.png|.png)|manifest.json)$ /favicon/$1 [L]
# exclude editor path
RewriteRule ^app\/ - [L]
# handle all seo files
RewriteRule ^(epndomain.txt|LiveSearchSiteAuth.xml|google[A-Za-z0-9]+.xml|[A-Za-z0-9]+.txt|(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z]{2,3})[A-Za-z0-9]+.html|robots.txt|sitemap.xml)$ display.php?seo=$1 [NC,L]
# ignore physical images, scripts, and fonts
RewriteCond %{REQUEST_URI} !\.(jpg|png|bmp|gif|css|js|map|ttf|woff|woff2|svg|eot)$
# display page contents
RewriteRule ^(.*)$ display.php?page=$1 [NC,L,QSA]
# handle missing physical images, scripts and fonts
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ display.php?page=error&rewritten=1&missing=$1 [NC,L,QSA]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment