19 08年四月

Apache的Mod_rewrite 例子


防止GetRight和Curl来抓取网內的数据的代码

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^curl [OR]
RewriteCond %{HTTP_USER_AGENT} ^GetRight
RewriteRule ^.* - [F]

阅读全部»

贝贝爸 发表在 技术文章 | 1个评论

22 07年三月

随机变化的.jpg图片


实现的原理很简单,就是apache的url_rewrite功能+php程序
url_rewrite代码

  1. [test@test htdocs]$ cat .htaccess
  2. # BEGIN WordPress
  3. <IfModule mod_rewrite.c>
  4. RewriteEngine On
  5. RewriteRule ^images/logo\.jpg$ /test/randomimg.php [L]
  6. </IfModule>

php代码

  1. <?php
  2. /*
  3. * Created on 2007-3-20
  4. *
  5. * To change the template for this generated file go to
  6. * Window - Preferences - PHPeclipse - PHP - Code Templates
  7. */
  8. header("Content-Type: image/jpeg");
  9. $dir    = './images/';
  10.  
  11. $imgarr=array();
  12. if ($handle = opendir($dir)) {
  13.     while (false !== ($file = readdir($handle))) {
  14.         if (preg_match ("/(.*?)\.jpg$/i", $file) ) {
  15.                 array_push($imgarr,$dir.$file);
  16.         }
  17.     }
  18.     closedir($handle);
  19. }
  20. //srand ((float) microtime() * 10000000);
  21. readfile($imgarr[array_rand ($imgarr)]);
  22. ?>

只要把把要显示的图片放到
$dir目录里就可以了:)
效果点击这里,或者刷新本页面,看右上角的图片。

贝贝爸 发表在 原创技术文章 | 2个评论

17 07年三月

apache url_rewrite的一个规则


实现的目的就是:
访问http://www.domin.com/user/*.*时
全部rewrite到对应的http://www.domin.com/*.*
当然包含子目录
譬如对http://www.domin.com/user/news/A01.htm时
会对应到http://www.domin.com/news/A01.htm

  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteRule user/(.*)$ $1

放在“/”测试通过

贝贝爸 发表在 原创技术文章 | 等您写评论

美体小铺急救棒 the bodyshop body shop 美体小铺茶树精油 美体小铺接骨木花眼胶 美体小铺VE眼霜
27Q.0.620Ss.