I have a page that gets read by a third-party payment processor, which then presents the resulting HTML to the user. It's currently breaking because all the links to CSS and javascript files in the <head> are site-root-relative instead of absolute. Is there any way I can force these links to be absolute?

Thanks!

Comments

3cwebdev’s picture

I'm not sure I fully understand what the third party site is doing but one option may be to add/change the $base_url in /sites/default/settings.php to be the absolute path of your site.

Copied from settings.php:

/**
* Base URL (optional).
*
* If you are experiencing issues with different site domains,
* uncomment the Base URL statement below (remove the leading hash sign)
* and fill in the URL to your Drupal installation.
*
* You might also want to force users to use a given domain.
* See the .htaccess file for more information.
*
* Examples:
* $base_url = 'http://www.example.com';
* $base_url = 'http://www.example.com:8888';
* $base_url = 'http://www.example.com/drupal';
* $base_url = 'https://www.example.com:8888/drupal';
*
* It is not allowed to have a trailing slash; Drupal will add it
* for you.
*/
# $base_url = 'http://www.example.com'; // NO trailing slash!

cvedovini’s picture

Hello,
I have the same problem than the poster (need absolute links instead of relative ones) and tried specifying the $base_url in the settings.php but this does not solve the issue, links are still relative.

FYI I need this because I got an external tool fetching one of the page to send a newsletter and all links in the mail end up being relative thus the mail is broken

Any other idea (beside asking the developers to fix their broken newsletter tool)?
Thx,
Claude

jrchew’s picture

An improper way to accomplish absolute links would be to open up

includes/common.inc

scroll down to line 1413 (assuming you're using D6)

and set absolute to equal TRUE.

vheilman’s picture

I'm also looking for a fix here without hacking anything core.

nobody1225’s picture

I have the same problem

prinds’s picture

Check out the method used by the web_widget module to change relative path links to full url links

from web_widget.module


/**
 * Stores the fact that if we're inside web_widget processing.
 */
function web_widgets_inside_widget($in = NULL) {
  static $base_path;
  if ($in === TRUE) {
    $base_path = $GLOBALS['base_path'];
    $GLOBALS['base_path'] = url('', array('absolute' => TRUE, 'purl' => array('disabled' => TRUE)));
  }
  elseif ($in === FALSE) {
    $GLOBALS['base_path'] = $base_path;
  }
  static $inside = FALSE;
  if (is_null($in)) {
    return $inside;
  }
  else {
    $inside = $in;
  }
}

maybe you could use a similar approach for the pages requested by the third party processor

prinds’s picture

There is also a setting in settings.php called $base_url, that allows you to force the base_path of your site into a specific url

nathanjo’s picture

That won't fix the css/js to be absolute. Anyone found resolution how to?

matt@antinomia’s picture

If you follow prind's suggestion above and set the $_GLOBAL['base_path'] variable to your site's base path, the javascript/css header URLS will output as absolute links rather than relative ones.