Welcome Guest, Not a member yet? Register   Sign In
Domain and Subdomain sharing the same CI files
#1

[eluser]MEM[/eluser]
Please I need your help:

Issue:


I have the following domain:
http://www.mysite.com

I want to have the following subdomain:
http://admin.mysite.com

They both should share the same 'application' and 'system' folders (they are one level up on the host directory).

www
- www
- admin
private
- application
- system


When the user makes http://admin.mysite.com (a default login controller should be called).
When the user makes http://www.mysite.com (a default homepage controller should be called).

In this scenario, what shoud we put on the application/config.php file?
$config['base_url'] = "http://whats.should.I.put.here"; ?

[UPDATE]
Ok. I realise that is something to do with the router file but, the examples seem to be related with first segment of the URI, second segment of the URI...

But I believe:

http://admin.mysite.com is not on the first segment so, something like this:
$route['admin'] = 'admin/login/' or something, will never work. Confused

I just need a push to be on the right track please...
[/UPDADE]

Please I'm stuck here...
Márcio
#2

[eluser]Phil Sturgeon[/eluser]
You can't really do this without LOTS of hacking. I would recommend you do something like:

config.php

Code:
$config['base_url']  = 'http://'.$_SERVER['HTTP_HOST'].'/';

.htaccess

Code:
RewriteCond %{HTTP_HOST} ^admin.mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/admin/$1 [L]

That means if you go on admin.mysite.com it will redirect anything after the / to the admin controller. It also means your URL's will continue to work inside the admin section as you are telling CodeIgniter to use whatever HTTP_HOST it is being accessed under, and we already know that to be admin.mysite.com.

Let me know how it goes!
#3

[eluser]MEM[/eluser]
Thanks a lot for your reply.

[quote author="Phil Sturgeon" date="1251229829"]
.htaccess

Code:
RewriteCond %{HTTP_HOST} ^admin.mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/admin/$1 [L]

That means if you go on admin.mysite.com it will redirect anything after the / to the admin controller.[/quote]

Ok. But I suppose I will not have an admin controller. I will have an admin folder inside my application/controller/ called admin, and inside that folder, I would have my controllers.

For example:
Let's say I have a public product list method on my products controller, the correspondent URI should be something like this:
http://www.mysite.com/products/list

And it will point to: /private/application/controller/products.php

Let's say I have a private product insert method on my admin products controller, the correspondent URI should look like this:
http://admin.mysite.com/admin/products/insert

It will point to /private/application/controller/admin/products.php


Does your solution still applies here?
And more important...
If it was you, would you do something like this? Would you use a sub-domain like this, or do you believe that, since we are sharing so many resources between domain and subdomain, the subdomain gets a little bit "extra" on this scenario?

Regards,
Márcio
#4

[eluser]MEM[/eluser]
Phil Sturgeon, I thank you for your reply. After a while however, I realise that this was not a big thing to do. Since I'm CI newbie, I will stay with the admin folder solution for now.


Kind Regards and sorry for any inconvenience,
Márcio
#5

[eluser]Phil Sturgeon[/eluser]
Check out some soultions for getting admin folder structures working.

This method would work find if you follow the sub-directory route. Instead of a sub-directory you would have a sub-domain, which would be mapped to the sub0directory... if that makes sense. :-)




Theme © iAndrew 2016 - Forum software by © MyBB