I’m looking for a solution to support multiple domains on one webhosting account, which has to be done with htaccess. So the idea is, you call domainx and with htaccess the server “fakes” the webroot to a subfolder corresponding with the domain name. I allready have a “solution”, but this doesn’t work perfectly.
Problems I’ve got:
- Redirects through PHP (with base_url() of CodeIginiter), result in; for example “http://www.domein1.nl/domein1.nl/”.
- It doesn’t work on my local server.
So, the htaccess I’m currently using:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} domein1.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/domein1.nl/.*$
RewriteRule ^(.*)$ /domein1.nl/$1 [L]
RewriteCond %{HTTP_HOST} domein2.nl$ [NC]
RewriteCond %{REQUEST_URI} !^/domein2.nl/.*$
RewriteRule ^(.*)$ /domein2.nl/$1 [L]
</IfModule>
The CodeIgniter PHP-code for the base_url(). The server variable “SCRIPT_NAME” adds the second domain folder, marked as problem 1. This should’nt happen if the root folder is faked correctly; but is that actually possible?
if (isset($_SERVER['HTTP_HOST']))
{
$base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
$base_url .= '://'. $_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
And last but not least, it is’nt working on my local server while I do redirect through my hosts file:
192.168.2.9 local.domein1.nl
192.168.2.9 local.domein2.nl
Sooo.. How do I fix these problems? Thanks in advance!
Edit: The problem with my local server is fixed.. cough “sudo a2enmod rewrite” did the trick..
Edit2: Since stormdrain started about folder structure, here is mine to clarify the multiple CI applications.
Main .htaccess location / webroot
/public_html/.htaccess
domain1:
/application/domain1/ (domain1 application path)
/application/system/ (shared system path)
/public_html/domain1/index.php (CI domain1 index)
domain2:
/application/domain2/ (domain2 application path)
/application/system/ (shared system path)
/public_html/domain2/index.php (CI domain2 index)
Well, it seems impossible to do neatly through htaccess..
O well, I “fixed” it. My fix within the CodeIgniter index.php: I replaced the declaration of the variable $application_folder with the code beneath.
I also made a minor change to the system “url_helper”. Added this “static_url()” function, returning the URI to the path I save images/CSS/js etc.
Only minor thing I’ve got to figure out is how to split up things like robots.txt