Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 918181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:19:54+00:00 2026-05-15T18:19:54+00:00

I have a PHP site using MVC, which builds HTML dynamically for most requests.

  • 0

I have a PHP site using MVC, which builds HTML dynamically for most requests.
I’m updating my site to host images/static content on a cookieless domain.
Currently the images/css are written out as links to relative URLs.

The best I can think of for now is to change all html that writes out <img> tags and css links to use a PHP function which inserts an absolute URL with the cookieless domain instead of the relative URL. However, this involves a lot of change to code and there is potential to miss a few tags/links.

Any suggestions on a better way to handle this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:19:55+00:00Added an answer on May 15, 2026 at 6:19 pm

    The sed solution:

    Use sed on all you html files. You can loop through all files with PHP (or a script function). glob is a great function for this.

    <?php
    // this sed assumes you have 
    // <img src="imgs/example.png" />
    // and want to change it to
    // <img src="http://www.noCookies.com/imgs/example.png" />
    
    // 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);
    }
    ?>
    

    Edit – original answer follows:
    Another option option, which is probably just as slow or slower than the original is mod rewrite

    If you run Apache, and all the images are in a separate folders (even if they’re not, but then it’s more work), you could use mod_rewrite… something like this…? I’m a little rusty oon mod_rewrite, but you want to take the relative path, and switch it with an absolute path:

    RewriteEngine on
    RewriteRule ^media/images/(.*) http://noCookies.com/media/images/$1 [L]
    

    I think it’s definitely the way the go though. Then you can change the old img sources slowly over time. Or just keep the old ones and add in the correct img src for any new images you add.

    Here is the mod_rewrite documenation, which is a little opaque… Some of the tutorials on preventing image hotlinking could also be helpful

    I just remembered, this is a good mod_rewrite tips and tricks page

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 522k
  • Answers 522k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're page is not refreshing because the AJAX call is… May 16, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer You need a format string: for i,j in data: file.write('%-15s… May 16, 2026 at 9:26 pm
  • Editorial Team
    Editorial Team added an answer I went with open source openAL library Finch. May 16, 2026 at 9:26 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am using an objected oriented MVC framework in PHP (Kohana) and have kind
I'm getting more into jQuery and so have set up a HTML/Javascript/CSS base site
I'm about to do a PHP website using the MVC pattern. I am not
I have configuired PHP 5.3 on IIS 7 using the following instructions: http://www.php.net/manual/en/install.windows.iis7.php and
I am setting up a pre-built website built in php. The site was actually
All the examples I've seen of what and how MVC SHOULD be have used
I basically am working with an oldschool php cms based site in Russian, one
Over the last few weeks I have been studying the MVC design pattern for
I have a completed web app in PHP 5 + MySQL. I have not
All PHP pages are all running just fine on my site, except for one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.