Find all .htaccess files and replace content with PHP script -


i need create script find .htaccess files on server , replace content new content need in order pages seo friendly.

so far i've come across few scripts find .htaccess files need able open, replace content new , save proper permissions.

can me following code add functionality need?

<?php  function searchdir($dir) {    $dhandle = opendir($dir);    if ($dhandle) {       // loop through       while (false !== ($fname = readdir($dhandle))) {          // if element directory, , not start '.' or '..'          // call searchdir function recursively passing element parameter          if (is_dir( "{$dir}/{$fname}" )) {             if (($fname != '.') && ($fname != '..')) {                echo "searching files in directory: {$dir}/{$fname} <br />";                searchdir("$dir/$fname");             }          // if element .htaccess file replace content          } else {             if($fname == ".htaccess")             {                echo "replacing content of file ".$dir/$fname."<br />";                // need code editing files here.             }          }       }       closedir($dhandle);     } }  searchdir(".");   ?> 

modify else loop this

else {   if($fname == ".htaccess")   {    echo "replacing content of file ".$dir/$fname."<br />";    // need code editing files here.    $htaccess_content = " htaccess string " ;  // can assignment @ top    file_put_contents("{$dir}/{$fname}",$htaccess_content) ;   } } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -