Skip to content

Instantly share code, notes, and snippets.

@rumkin
Created August 16, 2012 09:49
Show Gist options
  • Save rumkin/3368954 to your computer and use it in GitHub Desktop.
Save rumkin/3368954 to your computer and use it in GitHub Desktop.
Apache general redirects
# Redirect from index
RewriteCond %{QUERY_STRING} ^$ [OR]
RewriteCond %{REQUEST_FILENAME} ^\/index$
RewriteRule ^index$ http://host.tld/ [NC,R=301,L]
# Redirect everythink to php
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z_][a-zA-Z0-9_\-\[\]\/\.]+)$ /?%1&path=$1 [NC,L]
# Redirect www.host.tld to host.tld
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.host\.tld$ [NC]
RewriteRule ^(.*)$ http://host.tld/$1 [R=301,L]
# Redirect images to image resizer, example: file.jpg?i200x100
RewriteCond %{QUERY_STRING} ^(i|o)\d+(x\d+)?$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.(jpg|jpeg|png))$ ?__uri__=/.image-resizer&image=$1 [QSA,NC,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment