2011-02-28 11 views
1

自分のサーバー上のすべての.htaccessファイルを検索し、自分のページをSEOフレンドリーにするために必要な新しいコンテンツに置き換えるスクリプトを作成する必要があります。すべての.htaccessファイルを見つけてコンテンツをPHPスクリプトに置き換えてください

これまではすべての.htaccessファイルを見つけるためのスクリプトがいくつか出てきましたが、すべてのコンテンツを新しいものに置き換えて適切な権限で保存する必要があります。

私が必要とする余分な機能を追加するには、次のコードを手伝ってもらえますか?

<?php 

function searchDir($dir) { 
    $dhandle = opendir($dir); 
    if ($dhandle) { 
     // loop through it 
     while (false !== ($fname = readdir($dhandle))) { 
     // if the element is a directory, and does not start with a '.' or '..' 
     // we call searchDir function recursively passing this element as a parameter 
     if (is_dir("{$dir}/{$fname}")) { 
      if (($fname != '.') && ($fname != '..')) { 
       echo "Searching Files in the Directory: {$dir}/{$fname} <br />"; 
       searchDir("$dir/$fname"); 
      } 
     // if the element is an .htaccess file then replace content 
     } else { 
      if($fname == ".htaccess") 
      { 
       echo "Replacing content of file ".$dir/$fname."<br />"; 
       // I need the code for editing the files here. 
      } 
     } 
     } 
     closedir($dhandle); 
    } 
} 

searchDir("."); 


?> 

答えて

0

は私のために動作します。この

else { 
    if($fname == ".htaccess") 
    { 
    echo "Replacing content of file ".$dir/$fname."<br />"; 
    // I need the code for editing the files here. 
    $htaccess_content = " Your htaccess string " ; // you can do this assignment at the top 
    file_put_contents("{$dir}/{$fname}",$htaccess_content) ; 
    } 
} 
+0

おかげで、とあなたの他のループを変更します。 – bikey77

関連する問題