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 8704571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:08:24+00:00 2026-06-13T03:08:24+00:00

in PHP, I’ve written a proxy function that accepts a url, user agent, and

  • 0

in PHP, I’ve written a proxy function that accepts a url, user agent, and other settings. Then the function makes a curl request for the website, and prints out that output with proper html content type headers into an iframe (this is necessary only because of my need to change some headers).

That proxied output often has lots of assets with relative URLS and actually inheret the hostname of my site, not the proxied site:

example:
[http://MYSITE.com/proxy?url=http://somesite.com] would return the html of [http://somesite.com]

in the response html, there is stuff like this:

<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">

The problem:

Instead of the asset looking for that asset at http://somesite.com/assets/ico/apple-touch-icon-144-precomposed.png, it actually tries to find it at http://MYSITE.com/assets/ico/apple-touch-icon-144-precomposed.png which is wrong.

The Question:

What do i need to do to get their relative-path assets to load properly via the proxy?

  • 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-06-13T03:08:25+00:00Added an answer on June 13, 2026 at 3:08 am

    How about the <base> tag? You can place it in the head and it will inform the browser what to use as the base path for all relative URLs on the page:

    <head>
        <base href="http://somesite.com/">
    </head>
    

    You could add it to each page that you serve with DOMDocument (Note this is for PHP5.4 because of the array dereferencing, but that’s easy fixed for earlier versions):

    if($contentType == 'text/html') {
        $doc = DOMDocument::loadHTML($html);
        $head = $doc->getElementsByTagName('head')[0];
    
        if(count($head->getElementsByTagName('base')) == 0) {
            $base = DOMDocument::createElement('base');
            $base->setAttribute('href', $urlOfPageDir);
        }
    
        $head->appendChild($base);
        echo $doc->saveHTML();
    }
    

    Take note that $urlOfPageDir must be the absolute URL of the directory in which the page resides. See this SO question for more on the base tag: Is it recommended to use the <base> html tag?

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

Sidebar

Related Questions

PHP: I have made up a function that returns an array. I would like
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
PHP's documentation on this function is a bit sparse and I have read that
PHP curl at our localhost works fine but not on any other server Here
PHP has PHP-FPM, a pool of PHP processes that run, are managed, go away
PHP has some pretty inconsistent parameters for functions (e.g. sometimes first haystack , then
PHP script to read in user action requests and parse them to their components.
PHP's mkdir returns false on failure. Failure can be: Folder already exists Some other
PHP's curl doesn't seem to include the Host header when doing a request: <?php
PHP funcitons are written in C and you can look at the source code

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.