跳到主要内容

php程序生成.htaccess文件方法

冰客 冰客 2008-9-6 14:26:23 7339 阅读
发表于 2008-9-6 14:26:23 | 显示全部楼层 |阅读模式
自己建一个.php文件,上传到需生成.htaccess文件的目录。文件内容如下(这是discuz的,其他建站程序请作相应修改)

  1. <?php
  2.    // echo $content;
  3.    $filename = ".htaccess";
  4.    $handle = fopen ($filename,"w"); //打开文件指针,创建文件
  5.    /*
  6.  检查文件是否被创建且可写
  7.    */
  8. $text1="RewriteEngine On\n";
  9. $text2="RewriteBase /discuz\n";
  10. $text3="RewriteRule ^archiver/((fid|tid)-[0-9]+\.shtml)$ archiver/index.php?$1\n";
  11. $text4="RewriteRule ^forum-([0-9]+)-([0-9]+)\.shtml$ forumdisplay.php?fid=$1&page=$2\n";
  12. $text5="RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.shtml$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2\n";
  13. $text6="RewriteRule ^space-(username|uid)-(.+)\.shtml$ space.php?$1=$2\n";
  14. $text7="RewriteRule ^tag-(.+)\.shtml$ tag.php?name=$1\n";

  15.    if (!is_writable ($filename)){
  16.     die ("文件:".$filename."不可写,请检查其属性后重试!");
  17.    }
  18.    if (!fwrite ($handle,$text1.$text2.$text3.$text4.$text5.$text6.$text7)){   //将信息写入文件
  19.     die ("生成文件".$filename."失败!");
  20.    }
  21.    fclose ($handle); //关闭指针
  22.   
  23.    die ("创建文件".$filename."成功!");
  24. ?>
复制代码
您需要登录后才可以回帖 登录 | 成为会员 微博登录

本版积分规则

标签云|小黑屋|科技先生

Powered by Discuz! X5.0 © 2001-2026 科技先生|京ICP备07036130号

在本版发帖返回顶部