Override l() function in Drupal
I'm currently working on a Dr开发者_JS百科upal site (6.*), which when in production mode will be accessed through some kind of http proxy, which means I will have to rewrite all the links for my custom theme if the $_SERVER['HTTP_X_FORWARDED_SERVER']
variable is set to the domain people will access the site from.
The site has a lot of internal linking, mostly through Views
. My thought is that the easiest way to solve this would be to hook into the url()
and/or the l()
functions and post process the url before returning it if HTTP_X_FORWARDED_SERVER
is set.
My problem is that I can't figure out how to hook into these functions, or if it's even possible without touching the core, has anyone had to do this? How did you solve it?
UPDATE: I guess I forgot to mention that the proxy will not be located on root level of the proxy domain, so I need to rewrite all urls (both internal links and paths generated by the system to css files and images etc)
Examples:
proxy.com/path -> site.com/lots/of/dirs
proxy.com/path/node/1 -> site.com/lots/of/dirs/node/1
proxy.com/path/sites/all/themes/mytheme/my.css -> site.com/lots/of/dirs/sites/all/themes/mytheme/my.css
I'm not sure if I completely understand what you need, but I think you should have a look at the custom_url_rewrite_inbound() and custom_url_rewrite_outbound() functions.
I ended up having to modify the core slightly, replacing the line below in bootstrap.inc
$server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
with
$host = $_SERVER['HTTP_X_FORWARDED_HOST'] ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST'];
$server = explode('.', implode('.', array_reverse(explode(':', rtrim($host, '.')))));
Then I just set up a new site folder with my proxy.com url and changed $base_url
and $cookie_domain
in the settings.php
精彩评论