zanetaylor
7/1/2011 - 2:19 PM

Kohana .htaccess

Kohana .htaccess

# 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] 
# 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]
# 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]
# 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.* 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]