自己建一个.php文件,上传到需生成.htaccess文件的目录。文件内容如下(这是discuz的,其他建站程序请作相应修改)
- <?php
- // echo $content;
- $filename = ".htaccess";
- $handle = fopen ($filename,"w"); //打开文件指针,创建文件
- /*
- 检查文件是否被创建且可写
- */
- $text1="RewriteEngine On\n";
- $text2="RewriteBase /discuz\n";
- $text3="RewriteRule ^archiver/((fid|tid)-[0-9]+\.shtml)$ archiver/index.php?$1\n";
- $text4="RewriteRule ^forum-([0-9]+)-([0-9]+)\.shtml$ forumdisplay.php?fid=$1&page=$2\n";
- $text5="RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.shtml$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2\n";
- $text6="RewriteRule ^space-(username|uid)-(.+)\.shtml$ space.php?$1=$2\n";
- $text7="RewriteRule ^tag-(.+)\.shtml$ tag.php?name=$1\n";
- if (!is_writable ($filename)){
- die ("文件:".$filename."不可写,请检查其属性后重试!");
- }
- if (!fwrite ($handle,$text1.$text2.$text3.$text4.$text5.$text6.$text7)){ //将信息写入文件
- die ("生成文件".$filename."失败!");
- }
- fclose ($handle); //关闭指针
-
- die ("创建文件".$filename."成功!");
- ?>
复制代码