CodeIgniter Forums
Microsite Installation As Controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Microsite Installation As Controller (/showthread.php?tid=45765)



Microsite Installation As Controller - El Forum - 10-05-2011

[eluser]davzie[/eluser]
Hi Guys,

I have a Microsite that we built into our CodeIgniter installation. We used the same installation as the Microsite uses the same libraries, controllers and configs etc. Here is an example of the routes.php file which shows what gets run when the microsite "bellhouse" or parentdomain.com/bellhouse is accessed:

Code:
$route['bellhouse'] = "bellhouse/index/home";
$route['bellhouse/(:any)'] = "bellhouse/index/$1";

This works fine when we go to http://parentdomain.com/bellhouse

Now I want thebellhouse.com (as an example) to show in the URL http://thebellhouse.com but invisibly rewrite to: thebellhouse.com/index.php?/bellhouse so that I can access the microsite directly with that domain.

Here is my .htaccess file:

Code:
# Rewrite That Shizzle
<IfModule mod_rewrite.c>

  Options +FollowSymLinks
  RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]


# This should reroute a domain like thebellhouse.com to index.php/bellhouse/arguments
# Currently it doesn't...
RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^thebellhouse(.*)$ [NC]
  <IfModule mod_php5.c>
          RewriteRule ^(.*)$ index.php/bellhouse/home [L]
  </IfModule>
  
  <IfModule !mod_php5.c>
          RewriteRule ^(.*)$ index.php?/bellhouse/home [L]
  </IfModule>



  # Sends the requset via index.php if the request isn't a real file or folder and thebellhouse isn't in the domain name
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  <IfModule mod_php5.c>
          RewriteRule ^(.*)$ index.php/$1 [L]
  </IfModule>
  
  <IfModule !mod_php5.c>
          RewriteRule ^(.*)$ index.php?/$1 [L]
  </IfModule>




</IfModule>

Options -MultiViews
# We don't need to tell everyone we're apache.
ServerSignature Off

I know the domain is getting detected but there is no change in where the URL is being written to.

Here is my $_SERVER variables when I goto the Microsites domain:

Code:
Array
(
    [HTTP_USER_AGENT] => Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.9.168 Version/11.51
    [HTTP_HOST] => thebellhouse.local
    [HTTP_ACCEPT] => text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
    [HTTP_ACCEPT_LANGUAGE] => en,en-US;q=0.9,ja;q=0.8,fr;q=0.7,de;q=0.6,es;q=0.5,it;q=0.4,pt;q=0.3,pt-PT;q=0.2,nl;q=0.1,sv;q=0.1,nb;q=0.1,da;q=0.1,fi;q=0.1,ru;q=0.1,pl;q=0.1,zh-CN;q=0.1,zh-TW;q=0.1,ko;q=0.1
    [HTTP_ACCEPT_ENCODING] => gzip, deflate
    [HTTP_CONNECTION] => Keep-Alive
    [PATH] => /usr/bin:/bin:/usr/sbin:/sbin
    [SERVER_SIGNATURE] =>
    [SERVER_SOFTWARE] => Apache
    [SERVER_NAME] => thebellhouse.local
    [SERVER_ADDR] => 127.0.0.1
    [SERVER_PORT] => 80
    [REMOTE_ADDR] => 127.0.0.1
    [DOCUMENT_ROOT] => /Users/davzie/Sites/eapc/httpdocs
    [SERVER_ADMIN] => [email protected]
    [SCRIPT_FILENAME] => /Users/davzie/Sites/eapc/httpdocs/index.php
    [REMOTE_PORT] => 50824
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_PROTOCOL] => HTTP/1.1
    [REQUEST_METHOD] => GET
    [QUERY_STRING] =>
    [REQUEST_URI] => /
    [SCRIPT_NAME] => /index.php
    [PHP_SELF] => /index.php
    [REQUEST_TIME] => 1317808647
    [argv] => Array
        (
        )

    [argc] => 0
)

I really can't figure this one out and am wondering how other people might have solved an issue like this, I am sure others have had similar requirements.

Hope you can help!