Hello, I'm trying to set up multiple Drupal sites on the same server, each on its own folder but I'm having issues trying to configure URLs to be relative to their drupal folder.

Here's the scenario:

  • Site 1 on folder /site1 and should be accessible by browsing http://[dynamic]/site1
  • Site 2 on folder /site2 and should be accessible by browsing http://[dynamic]/site2
  • ...
  • Site N on folder /siteN and should be accessible by browsing http://[dynamic]/siteN

A couple of things and restrictions to consider:

  • I need different Drupal cores so one Drupal multisite instance is not an option
  • The different sites are already functional, meaning that I'm not starting from scratch
  • I can't set subdomains since the server hosting these sites has no static ip (using dyndns alternatives is not an option)
  • I've set the RewriteBase /siteN for each .htaccess
  • The $base_url variable on settings.php is not set
  • I'm using Pathologic module for fixing URLs already in content and it seems it fixes those well

Current situation (ie. for Site 1):

  • Links/URLs that are displayed by different pieces of content are working correctly after setting up pathologic for the corresponding input filters. For example, if I have some php code on a content field that echoes something like '<a href="/whatever"></a>' the actual URLs ends up being http://[dynamic]/site1/whatever which is what I wanted.
  • Links/URLs that are echoed as '<a href="/whatever"></a>' from template files (ie. node.tpl.php) end up being http://[dynamic]/whatever but without the /site1 folder. These are the ones I need to fix. Unfortunately I can't change these URLs on all templates since there are too many so I need these URLs to get prepended with the /site1 folder.

Thanks in advance!

Comments

zeezhao’s picture

In general, when I use multiple folders like you have, I ensure that $base_url is set in the settings.php. In my own cases, no links/url in templates... Hence maybe you need to change using search/replace...?

Also, you can use something like this to print base path before links:

<?php print base_path() ?>
brian.gora@gmail.com’s picture

Thanks Zeezhao, but those links/url are all over the place inside many template files. The search and replace alternative is not that easy since those links are sometimes generated by concatenating variables and then echoing them.

I'm trying to workaround this by applying rewriting rules in .htaccess but I haven't been able to set those rules properly.

Garrett Albright’s picture

Use the l() or url() functions in your template file instead of writing the links "flatly" like that. In fact, Pathologic is really just an elaborate wrapper around url()…

brian.gora@gmail.com’s picture

Thanks for your suggestion Garrett, do you know how to configure .htaccess mod_rewrite rules in order to workaround this?

I'm not able to replace links inside my templates for all the sites that easily.

Garrett Albright’s picture

That would just increase your technical debt even further… even if I knew how to help you with that (I'm not an Apache user so I don't), I wouldn't, since it's such a bad idea. =/