Skip to content

Instantly share code, notes, and snippets.

@loonies
Last active August 28, 2018 05:45
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loonies/1058632 to your computer and use it in GitHub Desktop.
Save loonies/1058632 to your computer and use it in GitHub Desktop.
Kohana .htaccess
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
# Max file upload size
php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value memory_limit 64M
# Disable PHPSESSID in the URI
php_value session.use_trans_sid Off
# Disable directory browsing
Options -Indexes
# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Redirect other sub domains to the main domain (use only if set by VirtulaHost ServerAlias)
RewriteCond %{HTTP_HOST} !^www\.other\.com
RewriteRule ^(.*)$ http://www.main.com/ [R=301,L]
# Redirect non-ssl to ssl
RewriteCond %{HTTPS} off [NC]
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect non-ssl directory (e.g. admin, checkout) to ssl
RewriteCond %{HTTPS} off [NC]
RewriteRule ^admin https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Allow direct access to the static files,
# if the file does not exists it will prevent another round trip to the application
RewriteRule ^(?:static|media)\b.* - [L]
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system)\b - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
# It happens that default 'RewriteRule' doesn't work on some host.
# Note that full URL has to be preserved including the query string.
# Documenting rules that worked for the future reference.
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
RewriteRule ^(.*)$ index.php?/$1 [PT,QSA]
# Redirect www to non-www and use SSL for admin pages
RewriteCond %{HTTPS} off [NC]
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^admin https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect www to non-www
RewriteCond %{HTTPS} on [NC]
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
@gngchrs
Copy link

gngchrs commented Sep 14, 2015

Thanks, man. Struggled with this for like two hours.

@kolmesdx
Copy link

tanks

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