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-89387208417489605282007-07-02T19:10:00.000Z2007-07-04T20:51:09.820ZBlogger, PHP, and LabelsI'm in the process of updating my Blogger template so that my new <a href="http://help.blogger.com/bin/topic.py?topic=10275">Blogger labels</a> and their corresponding label pages have a reasonable user interface and are actually useful. My goals are to: <ul><li>Make it clear when a label page is being displayed by including the label name in the page title and in any relevant headers & sidebar sections.<br /></li><li>On the page for a label named <i>label</i>, display <a href="http://del.icio.us/Deflexion.com">my bookmarks</a> that are tagged with <i>label</i> on del.icio.us (and, of course, also display my blog items that are labeled with <i>label</i>).<br /></li></ul>The first step is to use PHP to get the label name into a variable, which I call $label. Here's how I do this: <pre><a href="http://help.blogger.com/bin/answer.py?answer=42059&topic=8930"><MainPage></a><br /><?php<br /><i> </i> $label = <a href="http://php.net/manual/en/function.strtoupper.php">strtoupper</a>(<a href="http://php.net/manual/en/function.basename.php">basename</a>(<a href="http://php.net/reserved.variables">$_SERVER['PHP_SELF']</a>));<br /><i> </i> if ($label == 'INDEX') {<br /><i> </i> <i> </i> $label = <a href="http://php.net/manual/en/language.types.null.php">NULL</a>;<br /><i> </i> }<br /><br /><i> </i> // Note: This assumes no label will be named index<br /><br />?><br /></MainPage><br /></pre>This sets the $label variable to the upper-cased label name if a label page is being displayed and to NULL if the top page (deflexiοn.com/index) is being displayed. Determining the label name is as simple as determining the page's filename (basename) because Blogger names each label page label.extension and <a href="http://deflexion.com/2005/11/blogger-permalinks-seem-permanent-but">I've set up my blog to use extensionless URLs</a>.<br /><br />Once the variable $label is set, I use code such as the following to unconditionally process statements:<br /><pre><?php<br /><i> </i> echo "$label Deflexions (bookmarks)";<br />?></pre>Note that this does the right thing on label pages and on the the top page (index). For example, on a label page this resolves to: <pre>LABEL Deflexions (bookmarks)</pre> And on the top page, this resolves to: <pre>Deflexions (bookmarks)</pre> To conditionally process statements, I use code like the following:<br /><pre><?php<br /><i> </i> if ($label) {<br /><i> </i> <i> </i> echo "↓ deflexions & reflexions labeled $label";<br /><i> </i> }<br />?></pre>Note that on the top page $label is <a href="http://php.net/manual/en/language.types.boolean.php">NULL, which is considered FALSE</a>, and statements inside the squiggly brackets will not be run.<br /><br />I'm still updating my template so things are kind of a mess at the moment. I'm posting this now because I'd love to get feedback on my PHP code and my template. Please post your thoughts and tips as a comment to this blog item - thank you!NMnoreply@blogger.com