tag:blogger.com,1999:blog-59413252008-07-26T15:34:53.403+01:00Deflexion.comNMnoreply@blogger.comBlogger1125tag:blogger.com,1999:blog-5941325.post-13243334845936714452008-03-26T12:34:00.012Z2008-05-27T20:08:20.589+01:00htaccess excerpts and notesHere are some excerpts from my <a href="http://httpd.apache.org/docs/trunk/howto/htaccess.html">.htaccess files</a>. I'm posting these because I often need to remember the syntax of these commands and it's easier to look at the commands here on my blog than to ssh to my <a href="http://www.dreamhost.com/r.cgi?43299">DreamHost</a> or <a href="http://viaverio.com/">Verio</a> web-hosting account and look at them there. Also, I hope these excerpts and notes will be useful to others.
<b><i>Note:</i></b> In the code below, a line that begins with a single hash (<code>#</code>) is code that is commented out and a line that begins with two hashes (<code>##</code>) is a comment about the code.
<b><big>Used Everywhere</big></b><pre>## Block viewing of .htaccess files
<Files .htaccess>
<tt> </tt> order allow,deny
<tt> </tt> deny from all
</Files>
## Do not let IP address xxx.xxx.xxx.xx access (GET) the site
## Uncomment these 5 lines if someone or something is abusing the site
## Note: 'GET' can be replaced by 'GET POST PUT'
# <Limit GET>
# <tt> </tt> order allow,deny
# <tt> </tt> allow from all
# <tt> </tt> deny from xxx.xxx.xxx.xx
# </Limit>
## If a directory is requested, do not list the files in the directory
<a href="http://httpd.apache.org/docs/trunk/mod/core.html#options">Options</a> -Indexes
## Next is sometimes needed, but might already be set in the server configuration
# <a href="http://httpd.apache.org/docs/trunk/mod/core.html#adddefaultcharset">AddDefaultCharset</a> UTF-8
## Next is needed if you use Rewrite rules
## (examples of RewriteCond and RewriteRule are in the sections below)
RewriteEngine On
## Next Rewrite option is often already set in the server configuration
## Uncomment if Rewrite rules don't work
# Options +FollowSymLinks</pre>
The next sections include examples that use the Apache mod_rewrite module. If they seem confusing, it's because they are! As <a href="http://en.wikipedia.org/wiki/Brian_Behlendorf">Brian Behlendorf</a>, one of the primary developers of the Apache web server, said: <blockquote><big>“</big>The great thing about mod_rewrite is it gives you all the configurability and flexibility of <a href="http://en.wikipedia.org/wiki/Sendmail">Sendmail</a>. The downside to mod_rewrite is that it gives you all the configurability and flexibility of Sendmail.<big>”</big></blockquote>This quote, along with some other good quotes, is on the <a href="http://httpd.apache.org/docs/">Apache Documentation</a> <a href="http://httpd.apache.org/docs/trunk/rewrite/">mod_rewrite</a> page.
<big><b>Used at Deflexion.com</b></big><pre>## Specify the <a href="http://www.iana.org/assignments/media-types/">MIME type</a> of unknown file extensions
## This is needed because <a title="Blogger permalinks seem permanent, but are they?" href="http://deflexion.com/2005/11/blogger-permalinks-seem-permanent-but">I use extensionless URLs at Deflexion.com</a>
## If default is HTML, use:
# DefaultType text/html
## If default is PHP, use:
<a href="http://httpd.apache.org/docs/trunk/mod/core.html#defaulttype">DefaultType</a> application/x-httpd-php
## If URL points to a directory, serve the first of these files that exist
<a href="http://httpd.apache.org/docs/trunk/mod/mod_dir.html#directoryindex">DirectoryIndex</a> index index.php index.html index.<a href="http://atomenabled.org/">atom</a>
## PHP include files are located in this directory
php_value include_path "/path/i/do/not/want/to/publish/on/my/blog/_shared"
## If 'http://deflexion.com/index' is requested, remove 'index'
## The goal is to get people & machines to link to 1 & only 1 URL for this page
## Details at Wikipedia's <a href="http://en.wikipedia.org/wiki/URL_normalization">URL normalization</a> (aka URL canonicalization)
## Another examples of URL canonicalization is in the Infinite Ink section below
## Note: '^[A-Z]{3,9}\ /' matches GET POST PROPFIND etc, followed by space slash
## This RewriteCond avoids infinite loops
<a href="http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html#rewritecond">RewriteCond</a> %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/
<a href="http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html#rewriterule">RewriteRule</a> ^index$ http://deflexion.com/ <a href="http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html#rewriteflags">[R=301,L]</a>
## <a href="http://en.wikipedia.org/wiki/URL_redirection">Redirect this URL</a>-path to the current URL
<a href="http://httpd.apache.org/docs/trunk/mod/mod_alias.html#redirect">Redirect</a> permanent /messaging/blogs/ <a title="Just What is a Blog? Atomizing, Distributing, and Re-Forming Content" href="http://deflexion.com/2004/01/just-what-is-blog-atomizing">http://deflexion.com/2004/01/just-what-is-blog-atomizing</a>
## For details about these RedirectMatch lines, see
## <a href="http://deflexion.com/2008/03/twitter-tinyurl-dots-dashes-and-my">Twitter, TinyURL, Dots, Dashes, and My htaccess File</a>
## Note: The order of these 5 RedirectMatch lines matters!
<a href="http://httpd.apache.org/docs/trunk/mod/mod_alias.html#redirectmatch">RedirectMatch</a> 301 ^/(2008/../[^.]*)\.([^.]*)\.([^.]*)\.([^.]*)\.([^.]*)\.([^.]*)$ http://deflexion.com/$1-$2-$3-$4-$5-$6
RedirectMatch 301 ^/(2008/../[^.]*)\.([^.]*)\.([^.]*)\.([^.]*)\.([^.]*)$ http://deflexion.com/$1-$2-$3-$4-$5
RedirectMatch 301 ^/(2008/../[^.]*)\.([^.]*)\.([^.]*)\.([^.]*)$ http://deflexion.com/$1-$2-$3-$4
RedirectMatch 301 ^/(2008/../[^.]*)\.([^.]*)\.([^.]*)$ http://deflexion.com/$1-$2-$3
RedirectMatch 301 ^/(2008/../[^.]*)\.([^.]*)$ http://deflexion.com/$1-$2
<tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> ^^^
<tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> '301' is equivalent to 'permanent'
</pre>
<big><b>Used at Infinite Ink</b></big><pre>## If the requested hostname is anything other than www.ii.com,
## rewrite it to www.ii.com
RewriteCond %{HTTP_HOST} !^www.ii.com$ <!-- [NC] -->
RewriteRule (.*) http://www.ii.com/$1 [R=301]
## Remove trailing 'index.html' from requested URLs
## See Note above about the regular expression '^[A-Z](3,9}\ /'
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.ii.com/$1 [R=301,L]
## Redirect this local URL-path to the current URL
Redirect permanent /communicate <a title="Make a Meta Comment" href="http://deflexion.com/2005/12/make-meta-comment">http://deflexion.com/2005/12/make-meta-comment</a></pre>
<!-- http://www.organicseo.org/URL_Rewriting.html http://www.webmasterworld.com/apache/3311558.htm http://hecker.org/site/uri-rewriting http://www.asrvision.com/web-design-tutorials/htaccess-tutorial.htm /http://hecker.org/site/uri-rewriting -->
Comments, suggestions, and questions are welcome!NMnoreply@blogger.com