tag:blogger.com,1999:blog-59413252008-04-23T19:51:47.778ZDeflexion.comNMnoreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5941325.post-13243334845936714452008-03-26T12:34:00.010Z2008-04-13T13:19:09.801Zhtaccess 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.<br /><br /><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.<br /><br /><b><big>Used Everywhere</big></b><pre>## Block viewing of .htaccess files<br /><Files .htaccess><br /><tt> </tt> order allow,deny<br /><tt> </tt> deny from all<br /></Files><br /><br />## Do not let IP address xxx.xxx.xxx.xx access (GET) the site<br />## Uncomment these 5 lines if someone or something is abusing the site<br />## Note: 'GET' can be replaced by 'GET POST PUT'<br /># <Limit GET><br /># <tt> </tt> order allow,deny<br /># <tt> </tt> allow from all<br /># <tt> </tt> deny from xxx.xxx.xxx.xx<br /># </Limit><br /><br />## If a directory is requested, do not list the files in the directory<br /><a href="http://httpd.apache.org/docs/trunk/mod/core.html#options">Options</a> -Indexes<br /><br />## Next is sometimes needed, but might already be set in the server configuration<br /># <a href="http://httpd.apache.org/docs/trunk/mod/core.html#adddefaultcharset">AddDefaultCharset</a> UTF-8<br /><br />## Next is needed if you use Rewrite rules<br />## (examples of RewriteCond and RewriteRule are in the sections below)<br />RewriteEngine On<br /><br />## Next Rewrite option is often already set in the server configuration<br />## Uncomment if Rewrite rules don't work<br /># Options +FollowSymLinks</pre><br /><br />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.<br /><br /><br /><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<br />## 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><br />## If default is HTML, use:<br /># DefaultType text/html<br />## If default is PHP, use:<br /><a href="http://httpd.apache.org/docs/trunk/mod/core.html#defaulttype">DefaultType</a> application/x-httpd-php<br /><br />## If URL points to a directory, serve the first of these files that exist<br /><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><br /><br />## PHP include files are located in this directory<br />php_value include_path "/path/i/do/not/want/to/publish/on/my/blog/_shared"<br /><br />## If 'http://deflexion.com/index' is requested, remove 'index'<br />## The goal is to get people & machines to link to 1 & only 1 URL for this page<br />## Details at Wikipedia's <a href="http://en.wikipedia.org/wiki/URL_normalization">URL normalization</a><br />## More examples of URL canonicalization are in the Infinite Ink section below<br />## Note: '^[A-Z]{3,9}\ /' matches GET POST PROPFIND etc, followed by space slash<br />## This RewriteCond avoids infinite loops<br /><a href="http://httpd.apache.org/docs/trunk/mod/mod_rewrite.html#rewritecond">RewriteCond</a> %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/<br /><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><br /><br />## Redirect this local URL-path to the current URL<br /><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><br /><br />## For details about these RedirectMatch lines, see<br />## <a href="http://deflexion.com/2008/03/twitter-tinyurl-dots-dashes-and-my">Twitter, TinyURL, Dots, Dashes, and My htaccess File</a><br />## Note: The order of these 5 RedirectMatch lines matters!<br /><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<br />RedirectMatch 301 ^/(2008/../[^.]*)\.([^.]*)\.([^.]*)\.([^.]*)\.([^.]*)$ http://deflexion.com/$1-$2-$3-$4-$5<br />RedirectMatch 301 ^/(2008/../[^.]*)\.([^.]*)\.([^.]*)\.([^.]*)$ http://deflexion.com/$1-$2-$3-$4<br />RedirectMatch 301 ^/(2008/../[^.]*)\.([^.]*)\.([^.]*)$ http://deflexion.com/$1-$2-$3<br />RedirectMatch 301 ^/(2008/../[^.]*)\.([^.]*)$ http://deflexion.com/$1-$2<br /><tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> ^^^<br /><tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> <tt> </tt> '301' is equivalent to 'permanent'<br /></pre><br /><br /><big><b>Used at Infinite Ink</b></big><pre>## If the requested hostname is anything other than www.ii.com,<br />## rewrite it to www.ii.com<br />RewriteCond %{HTTP_HOST} !^www.ii.com$ <!-- [NC] --><br />RewriteRule (.*) http://www.ii.com/$1 [R=301,L]<br /><br />## Remove trailing 'index.html' from requested URLs<br />## See Note above about the regular expression '^[A-Z](3,9}\ /'<br />RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/<br />RewriteRule ^(([^/]+/)*)index\.html$ http://www.ii.com/$1 [R=301,L]<br /><br />## Redirect this local URL-path to the current URL<br />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><br /><!-- 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 --><br />Comments, suggestions, and questions are welcome!NMnoreply@blogger.comtag:blogger.com,1999:blog-5941325.post-45820827664563609792008-03-25T08:57:00.005Z2008-03-25T11:01:00.287ZTwitter, TinyURL, Dots, Dashes, and My htaccess FileAfter <a href="http://twitter.com/nm/statuses/632059012">a</a> <a href="http://twitter.com/nm/statuses/632175862">number</a> <a href="http://twitter.com/nm/statuses/666652952">of</a> <a href="http://deflexion.com/2008/03/abloggerandtwitterexperiment">experiments</a> and reading & <a title="thread about 'questions about URLs in tweets'" href="http://groups.google.com/group/twitter-development-talk/browse_thread/thread/9b030491fee28e64/d60c5a4909d4d660">participating</a> in the <a href="http://groups.google.com/group/twitter-development-talk/topics?gvc=2">twitter-development-talk mailing list</a>, I can now tweet about updates to my pages without Twitter converting my URLs to TinyURLs. First, here's what I've learned about Twitter and TinyURLs: <blockquote>If a URL path in a tweet contains only forward slashes (/), dots (.), and alphanumeric characters, Twitter does not convert the URL to a TinyURL.</blockquote>I plan to start tweeting about pages when I update them and if a page's URL contains dashes, tweet it with the dashes replaced by dots. For example, <a href="http://twitter.com/nm/statuses/776697568">the tweet about this blog item</a> uses this URL: <pre><a href="http://deflexion.com/2008/03/twitter.tinyurl.dots.dashes.and.my">http://deflexion.com/2008/03/twitter.tinyurl.dots.dashes.and.my</a></pre> The .htaccess file on my server includes this line: <pre>RedirectMatch 301 ^/(2008/../[^.]*)\.([^.]*)\.([^.]*)\.([^.]*)\.([^.]*)\.([^.]*)$ http://deflexion.com/$1-$2-$3-$4-$5-$6</pre> which redirects the URL to this: <pre><a href="http://deflexion.com/2008/03/twitter-tinyurl-dots-dashes-and-my">http://deflexion.com/2008/03/twitter-tinyurl-dots-dashes-and-my</a></pre> which is the actual URL of the blog item. This way I maintain control of URLs that lead to my pages and TinyURL does not get to track and profile people who visit my pages via <a href="http://twitter.com/nm">my tweets</a>.<br /><br />If you have a suggestion for a better way to do this, please post a comment. For example, I'm wondering if it would be better to use RewriteCond & RewriteRule rather than RedirectMatch in my .htaccess file. Some thoughts about this are in <a href="http://wiki.apache.org/httpd/WhenNotToUseRewrite">WhenNotToUseRewrite</a> in the <a href="http://httpd.apache.org/docs/">Apache Documentation</a> <a href="http://wiki.apache.org/httpd/">Wiki</a>.NMnoreply@blogger.com