SED解决方案:
对所有HTML文件使用SED。您可以使用PHP(或脚本函数)遍历所有文件。
glob
是一个很好的功能。
// this sed assumes you have
//
// and want to change it to
//
// Loop through each .html file in current directory and create an .html2
// If satisfied w results can finalize .html2 files
// I use .html2 so you don't overwrite your original files
foreach (glob("*.html") as $file)
{
// You have to escape double quotes
$lookFor = 'src=\"imgs';
$replaceWith = 'src=\"http://www.noCookies.com/imgs';
// create the sed command:
// _g is to do a global search
$shellCommand = "sed s_{$lookFor}_{$replaceWith}_g {$file}";
// create a NEW file and open it
$fp = fopen("{$file}2", "w");
// preform sed and write it to the new file
fwrite($fp, shell_exec($shellCommand));
fclose($fp);
}
?>
编辑-原始答案如下:
另一个选项是mod rewrite,它可能和原来的一样慢或慢。
如果您运行apache,并且所有的图像都在一个单独的文件夹中(即使它们不是,但这样做更有效),那么您可以使用mod重写…像这样的……?我有点生疏,但你想用相对路径,用绝对路径切换:
RewriteEngine on
RewriteRule ^media/images/(.*) http://noCookies.com/media/images/$1 [L]
我想这绝对是一种方式。然后,您可以随着时间的推移缓慢地更改旧的img源。或者只保留旧的图像,并为您添加的任何新图像添加正确的img-src。