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']);
Files: 
CommentFileSizeAuthor
#3 633726-install.patch1007 bytesagentrickard

Comments

Status:Active» Needs review

Nice explanation. Isn't this normally done in .htaccess?

Is there a "normal" Drupal documentation page that refers to this technique?

I 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!

Status:Needs review» Fixed
StatusFileSize
new1007 bytes

Yes, added to INSTALL.txt.

Wow, how coincidental! I was banging my head on this very issue. Thank you for this excellent snippet!

Status:Fixed» Closed (fixed)

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

This saved my life. Thank you.

Are you saying to accomplish this all we need to do is add that code and no need to touch the htaccess ?

thks soooo - #6 me too
but i have A problem with login to panel :/