I have my Drupal installation in a subfolder on the server, so all my links are of the form: http://example.com/drupal/admin/etc.
In Drupal, you'd normally change the $base_url variable in the settings.php file to reflect this and hide the subfolder from the URL, but because I'm also using Domain Access, I can't change it.
I therefore went looking for a way of hiding the subfolder from the URL, and finally came across this post: http://drupal.org/node/217710#comment-718517
By adding the provided code to my settings.php file, I was able to hide the subfolder from the URL, and without breaking Domain Access!
I'd like to recommend that the code be added somewhere (install.txt?) so people in similar situations don't spend hours pulling their hair out like I did ;)
/**
* Set dynamic $base_url to remove subfolder from URL
*
* See: http://drupal.org/node/217710#comment-718517
*/
$base_root = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http';
$base_url = $base_root .'://'. preg_replace('/[^a-z0-9-:._]/i', '', $_SERVER['HTTP_HOST']);
Comment | File | Size | Author |
---|---|---|---|
#3 | 633726-install.patch | 1007 bytes | agentrickard |
Comments
Comment #1
agentrickardNice explanation. Isn't this normally done in .htaccess?
Is there a "normal" Drupal documentation page that refers to this technique?
Comment #2
BWPanda CreditAttribution: BWPanda commentedI was originally looking for a .htaccess solution, but couldn't find one...
I just did a search for 'dynamic $base_url', but couldn't find any book pages that explained this technique either...
I just think it's a very handy piece of code and thank you for posting it!
Comment #3
agentrickardYes, added to INSTALL.txt.
Comment #4
modctek CreditAttribution: modctek commentedWow, how coincidental! I was banging my head on this very issue. Thank you for this excellent snippet!
Comment #6
xjmThis saved my life. Thank you.
Comment #7
espirates CreditAttribution: espirates commentedAre you saying to accomplish this all we need to do is add that code and no need to touch the htaccess ?
Comment #8
barrabasah CreditAttribution: barrabasah commentedthks soooo - #6 me too
but i have A problem with login to panel :/
Comment #9
imsovru CreditAttribution: imsovru commentedfor those using ssl only sites, you can also set a dynamic base_url
$base_url = 'https://'.$_SERVER['SERVER_NAME'];
This will force HTTPS, should also add a rewrite to your .htaccess to always load https,