Hello All,

Regex is my weakest subject, looking for some help here..

I wish to replace:

<img src="domain.com/*">
// or
<img src="*.domain.com/*">

with a new subdomain..

<img src="http://sub.domain.com/*>

Of course compensating for:

  • It may have http or may not at the beginning (may be relative)
  • It must have http:// in the replacement
  • anything after the domain could vary, subfolders, etc
  • Bonus for me if it doesn't rely on exactly "img src" (allowing for img width= src=, etc)

I have been playing around with some expressions but to be honest they are too horrible to even post (yes, they are that bad) however I have been searching tutorials, etc but this is still to advanced for me..

Any help at all would be great!

Thanks in advance

    Thanks Bradgrafelman,

    I am actually re-thinking my position here. Rather than dealing with so much complication I may try to play with mod_sed.

    The intention is to parse a largely convoluted site to push images (for now, maybe more later) to CDN.

    It's only a matter of specifying a subdomain, but because the costs of SSL (and a portion of the site is ssl) is too much for the CDN i was going to apply it only to non-ssl.

    This can easily be done with mod_sed to avoid the https portion of the site and I think will be less overhead.

    Thank you - I should mark this thread resolved & move my query over to Linux help page to see if I can try this in mod_sed (I've been doing research since I posted).

    Thanks again.

      Bradgrafelman,

      Without getting into an EXTREMELY long explanation - I am not the original author of the site, and there is a lot going on.

      The image tags are spread throughout the database, static files (hundreds) and this needs to be moved to CDN for only http (not ssl) traffic.

      In any capacity I would have to have PHP parse the entire page every time, or mod_sed do the same, to me it's neutral, but rather than putting if http(s) statements I could just run it for non-ssl avoiding the condition all together once SSL.

      Unless you can suggest a better approach (yes - we are redeveloping the site, but I need interim solution)

        To change the static files, you could just have PHP parse every static file you have once and save any changes if some were made. Same goes for the database, just update the records that need changed. Then the new values will always be there and there will never be parsing just to serve up a page. Just a one time parsing to update the values, which you could of course do during non-peak hours.

          Write a Reply...