Jump to content

edit string in a .htaccess


andz

Recommended Posts

Hi

 

Is there a way to edit a a string in a textfile? For now, I only have the codes to write to a file. I also want to be able to edit the content of the .htaccess let say i will comment something like commenting the RewriteRule string. Is that possible?

 

The code below only works in appending ErrorDocument string on the existing .htaccess.

 

$htaccess = file_get_contents('.htaccess');

if (!preg_match('/^ErrorDocument 404 /', $htaccess, $matches)) {

 

# create htaccess file

$fp = fopen('.htaccess', 'a');

if ($fp) {

$str = 'ErrorDocument 404 '.$url;

fwrite($fp, $str);

}

fclose($fp);

 

}

Link to comment
https://forums.phpfreaks.com/topic/206525-edit-string-in-a-htaccess/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.