When used to build the path to a Drupal file (like any of the *.php at the install root) instead of menu-generated URL, the url being generated by url() is incorrect if clean urls are off.

It can be worked around using 'script' in the $options array like url('<front>', array('script' => 'xmlrpc.php', 'absolute' => TRUE));, but this feels like a kludge, and definitely less clean than just url('xmlrpc.php', array('absolute' => TRUE)), especially since the latter works (if by chance) when clean urls are on.

Maybe this was unavoidable for performance reasons, but I could not find the issue discussing it.

Comments

robloach’s picture

Status: Active » Fixed

Try out....

url('xmlrpc.php', array(
  'absolute' => TRUE,
  'alias' => TRUE, // URL is already an alias.
))
dave reid’s picture

You shouldn't use URL for those.

echo $GLOBALS['base_url'] . '/xmlrpc.php';
dave reid’s picture

@Rob Loach: That will still fail if clean URLs are disabled.

fgm’s picture

Status: Fixed » Active

@Dave Reid: was this ever discussed anywhere ?

- By directly using a PHP superglobal, we are missing on the possibility of using an alterator to override the use of such a file.
- More generally, "user" (non-core) code does not normally use plain PHP globals anyway but uses the API. Do we really want to break the pattern ?

I really asked myself this question when noticing use of a construct similar to #2 in existing contrib code. Unless there was a discussion I did not find where this was agreed upon, I do not feel this can really be considered fixed yet.

Or maybe it should be redefined not as a D7 bug but a D8 feature ?

dave reid’s picture

We use this way in core to provide links to cron.php and update.php, so I'm not sure what exactly the 'bug' is since contrib can always follow the example set by core. We can create a feature request to possibly make an API function, but I don't really see too much of a need for it.

heine’s picture

There's no bug here.

$path The internal path or external URL being linked to, such as "node/34" or "http://example.com/foo"

cron.php is not a 'path'.

dave reid’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.