<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: rewritemap code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 17:35:14 GMT</pubDate>
    <description>DZone Snippets: rewritemap code</description>
    <item>
      <title>Using Apache with RewriteMap and a text file</title>
      <link>http://snippets.dzone.com/posts/show/4699</link>
      <description>This code will read a text file using Apache then upon a user request, look for a url containing /l/ eg. http://mysite.com/l/digg and rewrite the URL in full eg. http://mysite.com/gwd/feed/digg.html . The example file is shown here for completeness.&lt;br /&gt;&lt;br /&gt;RewriteMap uses a text file as a convenient alternative for the administrator when declaring many rewrite rules. Code based on the article from ONLamp.com -  A Day in the Life of #Apache http://urltea.com/1vwb&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;file name="links.txt" location="/var/www/localhost/"&gt;&lt;br /&gt;scotsman /gwd/feed/scotsman.html&lt;br /&gt;digg /gwd/feed/digg.html&lt;br /&gt;&lt;/file&gt;&lt;br /&gt;&lt;br /&gt;&lt;IfModule mod_rewrite.c&gt;&lt;br /&gt;RewriteEngine on&lt;br /&gt;RewriteMap links txt:/var/www/localhost/links.txt&lt;br /&gt;RewriteRule ^/l/(.*) ${links:$1|http://mysite.com/} [R]&lt;br /&gt;&lt;/IfModule&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Note: The [R] at the end of RewriteRule means redirect, to have a clean url simply remove that switch.&lt;br /&gt;&lt;br /&gt;*update 15-Feb-08 *&lt;br /&gt;Restart Apache rather reloading the module when switching redirection on or off for a RewriteRule.  The Apache version 2.2.6 (Unix) didn't pick up my settings correctly when I tried /etc/init.d/apache2 reload, instead I needed to use /etc/init.d/apache2 restart.</description>
      <pubDate>Thu, 25 Oct 2007 22:51:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4699</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
