$base_path -relative site root referral- broken in combination with SEF
| Project: | Administration |
| Version: | 4.7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | by design |
Jump to:
When using $base_path in a theme, it is supposed to return a relative url to the site's root url. This doesn't work when SEF is enabled _and_ a user is browsing the site in more than 1 directory in depth.
Example:
A theme links to an external stylesheet/script. This should be done following the example described at http://drupal.org/node/25297#base . Resulting in:
<script type="text/javascript" src="<?php print base_path() . path_to_theme() ?>/js/script.js"></script>When search engine friendly URLs are enabled, and a user is visiting the page www.example.com/user, the base_path() works like a charm, so does the path_to_theme().
But when a user is visiting a page like www.example.com/user/2, the base_path() returns "/", resulting in a browser looking for a script located at www.example.com/user/themes/currenttheme/js/script.js
Especially when a theme has a lot of external files, this will result in waiting for a page to load. (And of course a theme that's not functioning completely).
I think a patch should be applied in bootstrap.inc:
/**
* Loads the configuration and sets the base URL correctly.
*/ 148-177

#1
I can confirm this, it worked for a few hours and then I suddenly started to get this issue
#2
And it still exists AFTER deactivating the module, now this is critical. When I deactivated SEF i works again, but that's no final solution. Must mention that also use i18n, but deactivating it doesn't have any effect.
#3
You need a leading slash to designate it as an absolute url. All base_path() does is give you the path from root.
<script type="text/javascript" src="<?php print '/'. base_path() . path_to_theme() ?>/js/script.js"></script>or even better, use url():
<script type="text/javascript" src="<?php print url(path_to_theme() .'/js/script.js') ?>"></script>#4
Correction, The leading slash should come from the $base_url var inside settings.php. Make sure a leading slash is there. It's still not a bug. Just misconfigured.