Apache

Categories:

add WWW's to no WWW's

RewriteEngine on
 
# 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,
# (<a href="http://example.com/" title="http://example.com/">http://example.com/</a>... will be redirected to <a href="http://www.example.com/" title="http://www.example.com/">http://www.example.com/</a>...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#

Block access to SVN files via apache .htaccess

# Block access to SVN files to the outside world
<IfModule mod_rewrite.c>
  RewriteRule ^(.*/)?\.svn/ - [F,L]
  ErrorDocument 403 "Access Forbidden"
</IfModule>

Jooma remove index.php? from url

RewriteCond %{query_string} ^([a-zA-Z0-9\-\/\.]+)$ [NC]
RewriteRule ^(.*)$ <a href="http://example.com/phrase%1" title="http://example.com/phrase%1">http://example.com/phrase%1</a>? [R=301,L]

Jooma Redirect (via Rewrite) example

RewriteCond %{query_string} ^\/blog\/.*$ [NC]
RewriteRule ^(.*)$ <a href="http://example.com/blog/" title="http://example.com/blog/">http://example.com/blog/</a>? [L,R=301]

This takes the query string, evaluates it, and then redirects to a url and discards the query sting.

Force the server to treat .html files as if they were .php

<FilesMatch ".html">
ForceType application/x-httpd-php
</FilesMatch>

RedirectMatch

Forward requests for local files to Amazon S3

RedirectMatch /path/to/assets/folder/(.*) http://s3.amazonaws.com/domain/assets/folder/$1

301 Redirect

Redirect 301 /path/to/file.html http://www.domain.com/path/to/new-file.html