Skip to main content

Large list of Apache .htaccess examples specifically for MediaTemple (GS).

# Example .htaccess File
# Created by Brandon
# Learn more at http://kb.mediatemple.net
# (mt) Forums - http://kb.mediatemple.net/questions/824/
# (mt) System Status - http://status.mediatemple.net
# (mt) Statement of Support - http://mediatemple.net/support/statement/

# What is an .htaccess file? - http://kb.mediatemple.net/questions/19/
# In-depth information on .htaccess files. - http://kb.mediatemple.net/questions/515/

# Instructions
# Remove the "#" to uncomment any line that you wish to use, but be sure not to uncomment the Description.
# As a configuration file, .htaccess is very powerful, even the slightest syntax error (like a missing space) can result in severe server malfunction.

# Basic REDIRECTS (http://kb.mediatemple.net/questions/242/)
#######################################################################################

# This allows you to redirect your entire website to any other domain
#Redirect 301 / http://kb.mediatemple.net/

# This allows you to Redirect index to specific subfolder
#Redirect /index.html http://mt-example.com/newdirectory/

# Redirect old file path to new file path
#Redirect /olddirectory/oldfile.html http://mt-example.com/newdirectory/newfile.html

# redirect a specific file via 301
#redirect 301 /current/currentfile.html http://www.newdomain.com/new/newfile.html

# Index Page & Browsable Directories
#######################################################################################

# Provide Specific Index Page (Set the default handler)
#DirectoryIndex index.html

# This allows you to make a directory browsable - (http://kb.mediatemple.net/questions/18/)
#Options +Indexes

# Don't show directory listings for URLs which map to a directory.
#Options -Indexes

# PHP Versions
#######################################################################################

# Provide a specific version of php for web applicatons - (http://kb.mediatemple.net/questions/244/)
#Action php5-script /gs-bin/php-5.1.6-6
#AddHandler php5-script .php

# Basic mod_rewrite (http://kb.mediatemple.net/questions/85/)
#######################################################################################

# Enable Symbolic Links
#Options +FollowSymLinks

# enable basic rewriting
#RewriteEngine on

# File Types
#######################################################################################
# prevent display of select file types
#IndexIgnore *.wmv *.mp4 *.avi *.etc

# serve foo files as php files
#AddType application/x-httpd-php .foo

# serve foo files as cgi files
#AddType application/x-httpd-cgi .foo

# instruct browser to download multimedia files
#AddType application/octet-stream .avi
#AddType application/octet-stream .mpg
#AddType application/octet-stream .wmv
#AddType application/octet-stream .mp3
#AddType application/octet-stream .mov

# Using server side includes - SSI (http://kb.mediatemple.net/questions/10/)
#Options +Includes
#AddHandler server-parsed .shtml .html .htm

# Custom Error Pages (http://kb.mediatemple.net/questions/8/)
######################################################################################

#ErrorDocument 401 /nopasswd.html
#ErrorDocument 403 /error_pages/forbidden.html
#ErrorDocument 404 /not_found.html

# CGI (http://kb.mediatemple.net/questions/30/)
#######################################################################################

# Allows you to execute .cgi files outside of cgi-bin
#AddHandler cgi-script .cgi
#Options +ExecCGI

# Allows you to run cgi scripts that end with the .pl extension
#AddHandler cgi-script .pl

# Redirect WWW and Non-WWW
#######################################################################################

# If your site can be accessed both with and without the www. prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the www. prefix. Choose ONLY one option:

# To redirect all users to access the site WITH the www. prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:

#RewriteCond %{HTTP_HOST} ^example.com$ [NC]
#RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

# To redirect all users to access the site WITHOUT the www. prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# adapt and uncomment the following:

#RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
#RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

# Require SSL (Secure Sockets Layer) or https://
#######################################################################################

# An easy to way to always redirect the user to secure connection (https://) can be accomplished with the following lines:
#RewriteEngine On
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*)$ https://www.mt-example.com/$1 [R,L]

# In case you wish to force HTTPS for a particular folder you can use the following:
#RewriteEngine On
#RewriteCond %{SERVER_PORT} 80
#RewriteCond %{REQUEST_URI} somefolder
#RewriteRule ^(.*)$ https://www.mt-example.com/somefolder/$1 [R,L]

# Wordpress Tricks
#######################################################################################

# Wordpress Permalinks
# If WordPress is installed in the domain html directory, WordPress creates and uses the following htaccess directives:

#<IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteBase /
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule . /index.php [L]
#</IfModule>

# Wordpress Permalinks
# If WordPress is installed in some subdirectory called 'foo', WordPress creates and uses the following htaccess directives:

#<IfModule mod_rewrite.c>
# RewriteEngine On
# RewriteBase /foo/
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule . /foo/index.php [L]
#</IfModule>

# Secure WordPress Contact Forms
# Protect your insecure WordPress contact forms against online unrighteousness by verifying the domain from whence the form is called.
# Remember to replace the domain.com and contact.php with your domain and contact-form file names, respectively.

#RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
#RewriteCond %{REQUEST_POST} .*contact.php$
#RewriteRule .* - [F]