tag:blogger.com,1999:blog-59413252008-04-23T19:51:47.778ZDeflexion.comNMnoreply@blogger.comBlogger3125tag: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.comtag:blogger.com,1999:blog-5941325.post-1133383135691185972005-11-30T20:18:00.000Z2007-07-17T16:23:37.370ZBlogger permalinks seem permanent, but are they?I think I've now <a href="http://help.blogger.com/bin/topic.py?topic=8917">set up Blogger</a> and the <code>.htaccess</code> file [*] at <a title="DreamHost.com" href="http://www.dreamhost.com/r.cgi?iidotcom/shared/comparison.html">my web-hosting provider</a> so that all the reflexion archive-page URLs and the <span style="font-weight: bold; font-style: italic;">new</span> reflexion item-page URLs (permalinks) have no extension. I want this because I don't want to be locked in to the <code>.php</code> extension that I've been using, for example, I might switch from <a title="PHP: Hypertext Preprocessor" href="http://deflexion.com/labels/php">PHP</a> to another scripting language at some point in the future, and because extensionless URLs are nice [**].<br /><br />What I want, but haven't been able to figure out how to do, is to change the permalink of all my old reflexions. Does anyone know how to do this in Blogger or via the Blogger API? I tried turning off "Post Pages", republishing, turning "Post Pages" back on, and republishing again, but Blogger remembers the old permalinks. I can understand why the Blogger developers would do this, since they are supposed to be <span style="font-weight: bold;">perma</span>links, but I've used these URLs for less than a week and I can solve the problem of broken bookmarks and broken links via <code>.htaccess</code> tricks.<br /><br />If anyone has any suggestions, please leave a comment here. Or just leave a comment so I know that someone has read this -- don't be shy!<br /><br /><b><i>Update:</i></b> It turns out that when I edit an old reflexion and then republish it, it gets a new extensionless URL. I'm slowly going through my old posts and turning on comments, removing extraneous <a href="http://en.wikipedia.org/wiki/Newline">newlines</a>, and republishing with extensionless URLs.<br /><br /><small>[*] I use the following <code>.htaccess</code> lines tell the Apache web server that file names with no extension are to be interpreted as PHP files: <pre><i> </i> DefaultType application/x-httpd-php<br /><i> </i> DirectoryIndex index index.php index.html</pre> [**] To learn about the value of permalinks and extensionless URLs, see: <ul><li><a href="http://www.w3.org/Provider/Style/URI">Cool URIs don't change</a> by <a href="http://en.wikipedia.org/wiki/Tim_Berners_Lee">Tim Berners-Lee</a></li><li><a href="http://diveintomark.org/archives/2003/08/15/slugs">Cruft-free URLs in Movable Type</a> by <a href="http://diveintomark.org/">Mark Pilgrim</a></li><li>Wikipedia: <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator">Uniform Resource Locator</a>: <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator#Clean_URLs">Clean URLs</a></li></ul></small>NMnoreply@blogger.com