Skip to content

Instantly share code, notes, and snippets.

@geocine
Created August 20, 2013 03:17
Show Gist options
  • Save geocine/6276745 to your computer and use it in GitHub Desktop.
Save geocine/6276745 to your computer and use it in GitHub Desktop.
rewrite (.html <-> .htm) -> .php -> root
# rewrite .html to .htm only if .html does not exist and .htm exist
RewriteCond %{REQUEST_FILENAME} (.*)\.html$
RewriteCond %1\.html !-f
RewriteCond %1\.htm -f
RewriteRule ^(.*)\.html$ $1.htm [L]
# rewrite .htm to .html only if .htm does not exist and .html exist
RewriteCond %{REQUEST_FILENAME} (.*)\.htm$
RewriteCond %1\.htm !-f
RewriteCond %1\.html -f
RewriteRule ^(.*)\.htm$ $1.html [L]
# rewrite .html to .php only if .html does not exist and .php exist
RewriteCond %{REQUEST_FILENAME} (.*)\.html$
RewriteCond %1\.html !-f
RewriteCond %1\.php -f
RewriteRule ^(.*)\.html$ $1.php [L]
# rewrite .htm to .php only if .htm does not exist and .php exist
RewriteCond %{REQUEST_FILENAME} (.*)\.htm$
RewriteCond %1\.htm !-f
RewriteCond %1\.php -f
RewriteRule ^(.*)\.htm$ $1.php [L]
# redirect to homepage if file does not exist and is not under blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !blog/
RewriteRule . / [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment