0

I have a site with clean URLs enabled and in a test I've written, I compare the current drupalGetHeader('location') to file_create_url($file->uri). The tests passes on my site, but on the qa.drupal.org testbot (and, presumably, on any site that doesn't have clean URLs enabled) the test fails.

Is there an API function that's more clean-URL-reflective to file_create_url()?

  • With DrupalPublicStreamWrapper, the URL returned from DrupalPublicStreamWrapper::getExternalUrl() doesn't contain ?q=. I would say it is already clean-URLs agnostic. – kiamlaluno Jan 25 '13 at 21:35
  • It doesn't create a usable URL if clean URLs are enabled though, since it creates something other than the actual path. – beth Jan 25 '13 at 21:37
  • 1
    Since it is the URL for an actual file, it doesn't need to use the 'q' query parameter. If you have a file in sites/default/files, its URL is always http://<domain.name>/sites/default/files/<filename> whenever clean URLs are enabled, or not. – kiamlaluno Jan 25 '13 at 23:53
  • That makes sense. It is odd, then, that drupalGetHeader() returns a url with ?q= in it. Could this be an artifact of the redirect? – beth Jan 26 '13 at 3:27
0

I ended up using

str_replace('/?q=', '/'drupalGetHeader('location'));

So basically I gave up on including the ?q= that appears in the URL and instead stripped it from everything. It seems a little messy but it works for my purpose. Still doesn't really answer the question though.

drupal_parse_url() looked promising at first, but it didn't work because

drupal_parse_url(file_create_url($uri)) returned 'path' = http://example.com/path/to/file

but

drupal_parse_url(drupal_get_headers('location')) returned simply 'path' = /path/to/file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.