<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Geoinformatics &#187; Blog</title>
	<atom:link href="http://www.geoinformatics.cn/tag/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.geoinformatics.cn</link>
	<description>Arts and Sciences move me on ...</description>
	<lastBuildDate>Fri, 13 Jan 2012 10:29:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Add an icon to your website</title>
		<link>http://www.geoinformatics.cn/2006/08/how-to-add-an-icon-to-a-certain-website/</link>
		<comments>http://www.geoinformatics.cn/2006/08/how-to-add-an-icon-to-a-certain-website/#comments</comments>
		<pubDate>Sat, 12 Aug 2006 18:55:48 +0000</pubDate>
		<dc:creator>长安旧梦</dc:creator>
				<category><![CDATA[技术心得]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.geoinformatics.cn/index.php/category/miscellaneous/20060812107.html</guid>
		<description><![CDATA[radiohead 1. 你要自己定制或找一个pp的一个 Website  Icon ，规格要求为: 16×16 pixel bitmap，必须命名为 favicon.ico （为什么叫这个名字后面会讲到），放置在网站的根目录下. 2. 在你的网页中添加以下代码段： www.mydomain.com 替换为你的域名. 3. 在客户端打开你的网页，好好欣赏你的 Website Icon 吧. 将 Icon 命名为 favicon.ico 并放在 WebServer 的根目录下是因为当用户端使用的是 IE 浏览器，并且用户将你的网站保存到收藏夹中时，IE 浏览器会自动搜索 Web Server 的根目录，查找是否有 favicon.ico 文件，如果有，就作为收藏夹该页面的 Icon 。]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.radiohead.cn/blog/post/webicon.html" target="_blank">radiohead<br />
</a>1. 你要自己定制或找一个pp的一个 Website  Icon ，规格要求为: 16×16 pixel bitmap，必须命名为 favicon.ico （为什么叫这个名字后面会讲到），放置在网站的根目录下.<br />
2. 在你的网页中添加以下代码段：<a href="http://www.radiohead.cn/blog/post/webicon.html" target="_blank"> </a><br />
www.mydomain.com 替换为你的域名.<br />
3. 在客户端打开你的网页，好好欣赏你的 Website Icon 吧.</p>
<p>将 Icon 命名为 favicon.ico 并放在 WebServer 的根目录下是因为当用户端使用的是 IE 浏览器，并且用户将你的网站保存到收藏夹中时，IE 浏览器会自动搜索 Web Server 的根目录，查找是否有 favicon.ico 文件，如果有，就作为收藏夹该页面的 Icon 。<a href="http://www.radiohead.cn/blog/post/webicon.html" target="_blank"><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geoinformatics.cn/2006/08/how-to-add-an-icon-to-a-certain-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Syndicate Plugin</title>
		<link>http://www.geoinformatics.cn/2006/08/syndicate-plugin/</link>
		<comments>http://www.geoinformatics.cn/2006/08/syndicate-plugin/#comments</comments>
		<pubDate>Sun, 06 Aug 2006 19:32:35 +0000</pubDate>
		<dc:creator>长安旧梦</dc:creator>
				<category><![CDATA[技术心得]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.geoinformatics.cn/index.php/category/blog/2006080631.html</guid>
		<description><![CDATA[演示看右边的Syndicate   插件下载 首先，下载并解压缩到您的 WordPress 插件，然后在您的 WordPress 中激活该插件就可以了。 在适当的位置中加入以下代码既可.一般是加入到模板Sidebar 这个文件里. [UNKNOWN NODETYPE 7]?>?>?>?>?>]]></description>
			<content:encoded><![CDATA[<p>演示看右边的Syndicate   <a href="http://www.sb123.org/downloads/sem-subscribe-me.zip" target="_blank">插件下载</a></p>
<p>首先，下载并解压缩到您的 WordPress 插件，然后在您的 WordPress 中激活该插件就可以了。<br />
在适当的位置中加入以下代码既可.一般是加入到模板Sidebar 这个文件里.</p>
<p>[UNKNOWN NODETYPE 7]?>?>?>?>?></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geoinformatics.cn/2006/08/syndicate-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>htaccess 学习笔记</title>
		<link>http://www.geoinformatics.cn/2006/08/htaccess-%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/</link>
		<comments>http://www.geoinformatics.cn/2006/08/htaccess-%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/#comments</comments>
		<pubDate>Sun, 06 Aug 2006 17:05:47 +0000</pubDate>
		<dc:creator>长安旧梦</dc:creator>
				<category><![CDATA[技术心得]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.geoinformatics.cn/category/blog/2006080629.html</guid>
		<description><![CDATA[转载自Windix Apache的配置文件.htaccess是个难点，也是个重点。一直都没安下心来好好学学，甚至一直以为Redirect方法是属于mod_rewrite，用到的时候也都是糊里糊涂的。今天找到了一个很好的教程，一边学，一边写点心得。 updated: 不断修正一些小问题 Source: Comprehensive guide to .htaccess Officical reference: Directive Quick Reference 1 Introduction 介绍 文件名 .htaccess 属性 644 (RW-R–R–) htaccess会影响它所在目录下的所有子目录 注意大多数内容都要求保持在一行之内，不要换行，否则会引起错误 2 Error Documents 错误文档 Official document: ErrorDocument Directive ErrorDocument code document 例子 ErrorDocument 400 /errors/badrequest.html ErrorDocument 404 http://yoursite/errors/notfound.html ErrorDocument 401 “ Authorization Required ” (注意之后内容如果出现的双引号需要转义为 \”) 常见HTTP状态码 Successful Client Requests 200 [...]]]></description>
			<content:encoded><![CDATA[<p>转载自<a href="http://www.douzi.org/wp/index.php/articles/104" target="_blank">Windix</a><br />
Apache的配置文件.htaccess是个难点，也是个重点。一直都没安下心来好好学学，甚至一直以为Redirect方法是属于mod_rewrite，用到的时候也都是糊里糊涂的。今天找到了一个很好的教程，一边学，一边写点心得。</p>
<p>updated: 不断修正一些小问题</p>
<p>Source: <a href="http://www.javascriptkit.com/howto/htaccess.shtml" target="_blank">Comprehensive guide to .htaccess</a></p>
<p>Officical reference: <a href="http://httpd.apache.org/docs/2.0/mod/quickreference.html" target="_blank">Directive Quick Reference</a></p>
<p>1 Introduction 介绍<br />
文件名 .htaccess 属性 644 (RW-R–R–)<br />
htaccess会影响它所在目录下的所有子目录<br />
注意大多数内容都要求保持在一行之内，不要换行，否则会引起错误</p>
<p>2 Error Documents 错误文档<br />
Official document: <a href="http://httpd.apache.org/docs/2.0/mod/core.html#errordocument" target="_blank">ErrorDocument Directive</a></p>
<p>ErrorDocument code document<br />
例子<br />
ErrorDocument 400 /errors/badrequest.html<br />
ErrorDocument 404 http://yoursite/errors/notfound.html<br />
ErrorDocument 401 “</p>
<h1>Authorization Required</h1>
<p>”<br />
(注意之后内容如果出现的双引号需要转义为 \”)</p>
<p>常见HTTP状态码</p>
<p>Successful Client Requests</p>
<p>200 OK<br />
201 Created<br />
202 Accepted<br />
203 Non-Authorative Information<br />
204 No Content<br />
205 Reset Content<br />
206 Partial Content</p>
<p>Client Request Redirected</p>
<p>300 Multiple Choices<br />
301 Moved Permanently<br />
302 Moved Temporarily<br />
303 See Other<br />
304 Not Modified<br />
305 Use Proxy</p>
<p>Client Request Errors</p>
<p>400 Bad Request<br />
401 Authorization Required<br />
402 Payment Required (not used yet)<br />
403 Forbidden<br />
404 Not Found<br />
405 Method Not Allowed<br />
406 Not Acceptable (encoding)<br />
407 Proxy Authentication Required<br />
408 Request Timed Out<br />
409 Conflicting Request<br />
410 Gone<br />
411 Content Length Required<br />
412 Precondition Failed<br />
413 Request Entity Too Long<br />
414 Request URI Too Long<br />
415 Unsupported Media Type</p>
<p>Server Errors</p>
<p>500 Internal Server Error<br />
501 Not Implemented<br />
502 Bad Gateway<br />
503 Service Unavailable<br />
504 Gateway Timeout<br />
505 HTTP Version Not Supported</p>
<p>3 Password Protection 密码保护<br />
Official document: Authentication, Authorization and Access Control</p>
<p>假设密码文件为.htpasswd</p>
<p>AuthUserFile /usr/local/safedir/.htpasswd (这里必须使用全路径名)<br />
AuthName EnterPassword<br />
AuthType Basic</p>
<p>两种常见验证方式:<br />
Require user windix<br />
(仅允许用户windix登陆)<br />
Require valid-user<br />
(所有合法用户都可登陆)</p>
<p>Tip: 如何生成密码文件<br />
使用htpasswd命令(apache自带)</p>
<p>第一次生成需要创建密码文件<br />
htpasswd -c .htpasswd user1</p>
<p>之后增加新用户<br />
htpasswd .htpasswd user2</p>
<p>4 Enabling SSI Via htaccess 通过htaccess允许SSI(Server Side Including)功能<br />
AddType text/html .shtml<br />
AddHandler server-parsed .shtml<br />
Options Indexes FollowSymLinks Includes</p>
<p>DirectoryIndex index.shtml index.html</p>
<p>5 Blocking users by IP 根据IP阻止用户访问<br />
order allow,deny<br />
deny from 123.45.6.7<br />
deny from 12.34.5. (整个C类地址)<br />
allow from all</p>
<p>6 Blocking users/sites by referrer 根据referrer阻止用户/站点访问<br />
需要mod_rewrite模块</p>
<p>例1. 阻止单一referrer: badsite.com<br />
RewriteEngine on<br />
# Options +FollowSymlinks<br />
RewriteCond %{HTTP_REFERER} badsite\.com [NC]<br />
RewriteRule .* &#8211; [F]</p>
<p>例2. 阻止多个referrer: badsite1.com, badsite2.com<br />
RewriteEngine on<br />
# Options +FollowSymlinks<br />
RewriteCond %{HTTP_REFERER} badsite1\.com [NC,OR]<br />
RewriteCond %{HTTP_REFERER} badsite2\.com<br />
RewriteRule .* &#8211; [F]</p>
<p>[NC] &#8211; 大小写不敏感(Case-insensite)<br />
[F] &#8211; 403 Forbidden</p>
<p>注意以上代码注释掉了”Options +FollowSymlinks”这个语句。如果服务器未在 httpd.conf 的 段落设置 FollowSymLinks, 则需要加上这句，否则会得到”500 Internal Server error”错误。</p>
<p>7 Blocking bad bots and site rippers (aka offline browsers) 阻止坏爬虫和离线浏览器<br />
需要mod_rewrite模块</p>
<p>坏爬虫? 比如一些抓垃圾email地址的爬虫和不遵守robots.txt的爬虫(如baidu?)<br />
可以根据 HTTP_USER_AGENT 来判断它们<br />
(但是还有更无耻的如”中搜 zhongsou.com”之流把自己的agent设置为 “Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)” 太流氓了，就无能为力了)</p>
<p>RewriteEngine On<br />
RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Custo [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^HMView [OR]<br />
RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR]<br />
RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^larbin [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Wget [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Widow [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR]<br />
RewriteCond %{HTTP_USER_AGENT} ^Zeus<br />
RewriteRule ^.* &#8211; [F,L]</p>
<p>[F] &#8211; 403 Forbidden<br />
[L] &#8211; ?</p>
<p>8 Change your default directory page 改变缺省目录页面<br />
DirectoryIndex index.html index.php index.cgi index.pl</p>
<p>9 Redirects 转向<br />
单个文件<br />
Redirect /old_dir/old_file.html http://yoursite.com/new_dir/new_file.html</p>
<p>整个目录<br />
Redirect /old_dir http://yoursite.com/new_dir</p>
<p>效果: 如同将目录移动位置一样<br />
http://yoursite.com/old_dir -> http://yoursite.com/new_dir<br />
http://yoursite.com/old_dir/dir1/test.html -> http://yoursite.com/new_dir/dir1/test.html</p>
<p>Tip: 使用用户目录时Redirect不能转向的解决方法</p>
<p>当你使用Apache默认的用户目录，如 http://mysite.com/~windix，当你想转向 http://mysite.com/~windix/jump时，你会发现下面这个Redirect不工作:<br />
Redirect /jump http://www.google.com</p>
<p>正确的方法是改成<br />
Redirect /~windix/jump http://www.google.com</p>
<p>(source: .htaccess Redirect in “Sites” not redirecting: why?)</p>
<p>10 Prevent viewing of .htaccess file 防止.htaccess文件被查看</p>
<p>order allow,deny<br />
deny from all</p>
<p>11 Adding MIME Types 添加 MIME 类型<br />
AddType application/x-shockwave-flash swf</p>
<p>Tips: 设置类型为 application/octet-stream 将提示下载</p>
<p>12 Preventing hot linking of images and other file types 防盗链<br />
需要mod_rewrite模块</p>
<p>RewriteEngine on<br />
RewriteCond %{HTTP_REFERER} !^$<br />
RewriteCond %{HTTP_REFERER} !^http://(www/\.)?mydomain.com/.*$ [NC]<br />
RewriteRule \.(gif|jpg|js|css)$ &#8211; [F]</p>
<p>解析:<br />
若 HTTP_REFERER 非空 (来源为其他站点，非直接连接) 并且<br />
若 HTTP_REFERER 非(www.)mydomain.com开头(忽略大小写[NC]) (来源非本站)<br />
对于所有含有 .gif/.jpg/.js/.css 结尾的文件给出 403 Forbidden 错误[F]</p>
<p>也可指定响应，如下例显示替换图片</p>
<p>RewriteRule \.(gif|jpg)$ http://www.mydomain.com/angry.gif [R,L]</p>
<p>[R] &#8211; 转向(Redirect)<br />
[L] &#8211; 连接(Link)</p>
<p>13 Preventing Directory Listing 防止目录列表时显示<br />
IndexIgnore *</p>
<p>IndexIgnore *.jpg *.gif</p>
<p>Tips:<br />
允许目录列表显示: Options +Indexes<br />
禁止牧师列表显示: Options -Indexes<br />
显示提示信息: 页首 文件HEADER, 页尾 文件README</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geoinformatics.cn/2006/08/htaccess-%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache的rewrite技术</title>
		<link>http://www.geoinformatics.cn/2006/08/apache%e7%9a%84rewrite%e6%8a%80%e6%9c%af/</link>
		<comments>http://www.geoinformatics.cn/2006/08/apache%e7%9a%84rewrite%e6%8a%80%e6%9c%af/#comments</comments>
		<pubDate>Sun, 06 Aug 2006 15:32:04 +0000</pubDate>
		<dc:creator>长安旧梦</dc:creator>
				<category><![CDATA[技术心得]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.geoinformatics.cn/index.php/category/blog/27.html</guid>
		<description><![CDATA[做PHP项目中需要用到URL重定向技术，基本上的需求就是把比如 /user/heiyeluren 重定向到 /user.php?uid=heiyeluren 之类的URL上，当然，你也可以把 /article/200707291011.html重定向到 /article.php?id=200507291011 之类的，模拟好像是静态页面，能够隐藏URL真实地址，有助于雨鞋基本的安全防范等等。那么好像rewrite是个很好的解决办法。 要在Apache里运行rewrite的话，必须先安装mod_rewrite的组件，就是一个mod_rewrite.c文件，然后必须在./configure的时候要放上mod_rewrite就能安装。 一般配置rewrite的话，可以在httpd.conf里面配置，也能在网页当前目录的.htaccess文件里进行定义来决定重定向去那个文件，那样的话，就非常具有灵活性了，同样也能够适合虚拟主机用户来做。 我们看一个.htaccess文件的例子： 1 2 RewriteEngine On 3 RewriteBase / 4 RewriteCond %{REQUEST_FILENAME} -f [OR] 5 RewriteCond %{REQUEST_FILENAME} -d 6 RewriteRule ^.*$ &#8211; [S=42] 7 8 #RewriteRule ^share/$ /share.php [QSA,L] 9 RewriteRule ^tag/([^/]+)/?$ /user_tags.php?tag=$1 [QSA,L] 10 RewriteRule ^city/([^/]+)/?$ /user_city.php?tag=$1 [QSA,L] 11 #RewriteRule ^([^/]+)/day/([^/]+)/?$ /user_share.php?id=$1&#038;s=1&#038;selTime=$2 [QSA,L] 12 #RewriteRule [...]]]></description>
			<content:encoded><![CDATA[<p>做PHP项目中需要用到URL重定向技术，基本上的需求就是把比如 /user/heiyeluren 重定向到 /user.php?uid=heiyeluren 之类的URL上，当然，你也可以把 /article/200707291011.html重定向到 /article.php?id=200507291011 之类的，模拟好像是静态页面，能够隐藏URL真实地址，有助于雨鞋基本的安全防范等等。那么好像rewrite是个很好的解决办法。</p>
<p>要在Apache里运行rewrite的话，必须先安装mod_rewrite的组件，就是一个mod_rewrite.c文件，然后必须在./configure的时候要放上mod_rewrite就能安装。<br />
一般配置rewrite的话，可以在httpd.conf里面配置，也能在网页当前目录的.htaccess文件里进行定义来决定重定向去那个文件，那样的话，就非常具有灵活性了，同样也能够适合虚拟主机用户来做。</p>
<p>我们看一个.htaccess文件的例子：</p>
<p>1 <IfModule mod_rewrite.c><br />
2 RewriteEngine On<br />
3 RewriteBase /<br />
4 RewriteCond %{REQUEST_FILENAME} -f [OR]<br />
5 RewriteCond %{REQUEST_FILENAME} -d<br />
6 RewriteRule ^.*$ &#8211; [S=42]<br />
7<br />
8 #RewriteRule ^share/$ /share.php [QSA,L]<br />
9 RewriteRule ^tag/([^/]+)/?$ /user_tags.php?tag=$1 [QSA,L]<br />
10 RewriteRule ^city/([^/]+)/?$ /user_city.php?tag=$1 [QSA,L]<br />
11 #RewriteRule ^([^/]+)/day/([^/]+)/?$ /user_share.php?id=$1&#038;s=1&#038;selTime=$2 [QSA,L]<br />
12 #RewriteRule ^([^/]+)/day/([^/]+)/?$ /user_share.php?id=$1&#038;s=1&#038;selTime=$2 [QSA,L]<br />
13<br />
14 RewriteRule ^([^/]+)/day/([^/]+)/?$ /user_share.php?id=$1&#038;s=1&#038;selTime=$2 [QSA,L]<br />
15 RewriteRule ^([^/]+)/week/([^/]+)/?$ /user_share.php?id=$1&#038;s=2&#038;selTime=$2 [QSA,L]<br />
16 RewRiteRule ^([^/]+)/month/([^/]+)/?$ /user_share.php?id=$1&#038;s=3&#038;selTime=$2 [QSA,L]<br />
17<br />
18 RewriteRule ^([^/]+)/day/?$ /user_share.php?id=$1&#038;s=1    [QSA,L]<br />
19 RewriteRule ^([^/]+)/week/?$ /user_share.php?id=$1&#038;s=2   [QSA,L]<br />
20 RewriteRule ^([^/]+)/month/?$ /user_share.php?id=$1&#038;s=3  [QSA,L]<br />
21<br />
22 RewriteRule ^([^/]+)/?$ /user_share.php?id=$1    [QSA,L]<br />
23 </IfModule></p>
<p>比较长吧，我们就简单关注一下关键的内容。<IfModule></IfModule>之间就是定义的内容，RewriteEngine就是确定是否运行URL重写功能，RewriteBase就是基本的路径是什么，最关键的就是下面的RewriteRule，就是我们需要重写的规则了，这里应用了兼容Perl规则的正则表达式：</p>
<p>Text:<br />
.           匹配任意单个字符<br />
[chars]     匹配当前字符<br />
[^chars]    不匹配当前字符<br />
text1|text2 包含text1或者text2任何一个</p>
<p>Quantifiers:<br />
?           零个或者一个?号前的字符<br />
*           零个或者任意个任意长度的任意字符<br />
+           一个或者任意个任意长度的字符</p>
<p>Grouping:<br />
(text)      Grouping of text<br />
(either to set the borders of an alternative or<br />
for making backreferences where the Nth group can<br />
be used on the RHS of a RewriteRule with $N)</p>
<p>Anchors:<br />
^           匹配内容开始标记<br />
$           匹配内容结束标记</p>
<p>Escaping:<br />
\char       使用\来进行特殊字符的转义，包括&#8221;.[]()&#8221;等字符的转义</p>
<p>基本规则如上，比如下面的正则表达式：^/([^/]+)/~([^/]+)/(.*)$ 就是能够匹配象 /Language/~ Realname/&#8230;/File 这样的路径。</p>
<p>那么从这个角度去看上面的内容就比较容易理解了。我们简单看一下RewriteRule指令的规则：<br />
RewriteRule   访问的路径    需要指向的真实路径<br />
这样就很清楚了，比如说我要把/user/heiyeluren重定向到/user.php?uid=heiyeluren那么我的规则就必须这样：<br />
RewriteRule ^user/([^/]+)$  ^/user.php?uid=$2 [QSA,L]</p>
<p>举一反三，就很容易理解规则如何去写，也就能够理解上面规则脚本的内容了。</p>
<p>没有清楚的，请参考附上的链接，更深入的了解具体内容。写的不好请见谅。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.geoinformatics.cn/2006/08/apache%e7%9a%84rewrite%e6%8a%80%e6%9c%af/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Usage of Tag Cloud</title>
		<link>http://www.geoinformatics.cn/2006/08/usage-of-tag-cloud/</link>
		<comments>http://www.geoinformatics.cn/2006/08/usage-of-tag-cloud/#comments</comments>
		<pubDate>Sat, 05 Aug 2006 12:26:27 +0000</pubDate>
		<dc:creator>长安旧梦</dc:creator>
				<category><![CDATA[技术心得]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.geoinformatics.cn/index.php/category/blog/23.html</guid>
		<description><![CDATA[http://sw-guide.de/wordpress/category-tagging-plugin/]]></description>
			<content:encoded><![CDATA[<p><a href="http://sw-guide.de/wordpress/category-tagging-plugin/ " target="_blank">http://sw-guide.de/wordpress/category-tagging-plugin/ </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.geoinformatics.cn/2006/08/usage-of-tag-cloud/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Permalinks</title>
		<link>http://www.geoinformatics.cn/2006/08/using-permalinks/</link>
		<comments>http://www.geoinformatics.cn/2006/08/using-permalinks/#comments</comments>
		<pubDate>Thu, 03 Aug 2006 05:52:12 +0000</pubDate>
		<dc:creator>长安旧梦</dc:creator>
				<category><![CDATA[技术心得]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.geoinformatics.cn/index.php/category/blog/7</guid>
		<description><![CDATA[Permalinks are the permanent URLs to your individual weblog posts, as well as categories and other lists of weblog postings. A permalink is what another weblogger will use to refer to your article (or section), or how you might send a link to your story in an e-mail message. Especially when they are used to [...]]]></description>
			<content:encoded><![CDATA[<p>Permalinks are the permanent URLs to your individual weblog posts, as well as categories and other lists of weblog postings. A permalink is what another weblogger will use to refer to your article (or section), or how you might send a link to your story in an e-mail message. Especially when they are used to link to individual postings, once a story is posted, the URL to it should be permanent, and never change. Hence the &#8220;perma&#8221; in the name.</p>
<h1>Structure Tags</h1>
<p>You can use these tags to customize your &#8220;Pretty&#8221; or &#8220;Almost Pretty&#8221; permalinks.</p>
<dl>
<dt>%year%  </dt>
<dd>The year of the post, four digits, for example <tt><font face="Courier New">2004</font></tt> </dd>
<dt>%monthnum%  </dt>
<dd>Month of the year, for example <tt><font face="Courier New">05</font></tt> </dd>
<dt>%day%  </dt>
<dd>Day of the month, for example <tt><font face="Courier New">28</font></tt> </dd>
<dt>%hour%  </dt>
<dd>Hour of the day, for example <tt><font face="Courier New">15</font></tt> </dd>
<dt>%minute%  </dt>
<dd>Minute of the hour, for example <tt><font face="Courier New">43</font></tt> </dd>
<dt>%second%  </dt>
<dd>Second of the minute, for example <tt><font face="Courier New">33</font></tt> </dd>
<dt>%postname%  </dt>
<dd>A sanitized version of the title of the post. So “This Is A Great Post!” becomes “<tt><font face="Courier New">this-is-a-great-post</font></tt>” in the URI (see note below) </dd>
<dt>%post_id%  </dt>
<dd>The unique ID # of the post, for example <tt><font face="Courier New">423</font></tt> </dd>
<dt>%category%  </dt>
<dd>A sanitized version of the category name. Nested sub-categories appear as nested directories in the URI. </dd>
<dt>%author%  </dt>
<dd>A sanitized version of the author name. </dd>
</dl>
<p>These types of permalinks work on most systems without any problems, but there are still some conditions where problems occur.</p>
<dl>
<dt>Note on using only <tt><font face="Courier New">%postname%</font></tt>  </dt>
<dd>If you use postname as the only element in your permalinks to create a structure such as <tt><font face="Courier New">myblog.com/post-title</font></tt>, the rewrite rules may make it impossible to access pages such as your stylesheet (which has a similar format) or the <tt><font face="Courier New">wp-admin</font></tt> folder. It&#8217;s best to include some numeric data (e.g. the post ID or date) in the permalink to prevent this from happening. Additionally, WordPress v1.2.x requires the use of a date structure in order for some features, such as the calendar, to function properly. <tt><font face="Courier New">/%year%/%monthnum%/%day%/%postname%/</font></tt> is always a good start. </dd>
</dl>
<dl>
<dt>Note on using <tt><font face="Courier New">%category%</font></tt>  </dt>
<dd><tt><font face="Courier New">%category%</font></tt> does not work correctly with <em>some implementations</em> of mod_rewrite in Apache versions prior to 2. If you are using Apache 1 and experience problems with using <tt><font face="Courier New">%category</font></tt>, either do not use <tt><font face="Courier New">%category%</font></tt> in your permalink structure, or refer to <a class="external" title="http://isaacschlueter.com/plugins/i-made/lucky-13-rewrite/" href="http://isaacschlueter.com/plugins/i-made/lucky-13-rewrite/"><strong><font color="#192a72">Schlueterica&#8217;s plugin</font></strong></a><span class="urlexpansion"> (<em>http://isaacschlueter.com/plugins/i-made/lucky-13-rewrite/</em>)</span>. </dd>
</dl>
<dl>
<dt>Note on using <tt><font face="Courier New">%category%</font></tt> with multiple categories on a post  </dt>
<dd>Where you assign multiple categories to a post, only 1 can show up in the permalink. This will be the lowest numbered category (see <a title="Manage Categories SubPanel" href="/Manage_Categories_SubPanel"><strong><font color="#192a72">Manage Categories</font></strong></a>). The post will still be accessible through all the categories as normal. </dd>
</dl>
<dl>
<dt>Properly terminating permalinks  </dt>
<dd>It&#8217;s important to guarantee permalinks lead to individual posts within your custom URI, so make sure to end a virtual site structure with either <tt><font face="Courier New">%post_id%</font></tt> or <tt><font face="Courier New">%postname%</font></tt> </dd>
</dl>
<pre>/%year%/%monthnum%/%day%/%postname%/</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.geoinformatics.cn/2006/08/using-permalinks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

