1

I'm using CodeIgniter to build my first web app. For demo purposes, users can preview their site by simply using their Facebook username as a paramater (using public data from the Graph API). So they access their data using:

myurl.com/controller/function/**username**

However in the future I'd like users to be able to use their custom domain to view a similar page.

I've read around the topic but their doesn't seem to be an agreed solution. Some say I need to use mod_rewrite in .htaccess, some suggest using virtual hosts, some mention playing with $_SERVER requests to redirect users. There seem to be plenty of suggestions but not so many examples to help decide.

I'm quite happy to set up each domain manually (i.e. by editing .htaccess by hand), but I still would like to be able to use a single CodeIgniter installation.

So, how can I point multiple URLs/custom domains to a CodeIgniter URL, and what security implications are there?

Possible related link

Community
  • 1
  • 1
Joe W
  • 998
  • 6
  • 16
  • 36
  • 2
    Are you asking about subdomains (`http://username.example.com/`) or multiple URLs (`http://user-purchased-domain.com/`)? – birderic Oct 05 '11 at 21:24

1 Answers1

0

What version of CodeIgniter are you talking about?

I would probably go down the Virtual Hosts route to be honest. You could try setting up a wildcard Virtual Host so that if the called domain isn't setup on your server it will default to the CodeIgniter App..

This would be dynamic because all you do is setup the DNS for your clients domains to point to your server and they will all get the one instance of the CI app. This isn't secure though.

I would suggest having a CI function that all the domains are sent to before the main CodeIgniter app is kicked off.. This intermediary will then do some lookup into a DB table to see if the called domain is a permitted one. If not redirect away, if it is then load up the main CI app.

This should work well for CI 2.x as it can autodetect domains so you don't need to hardcode in the configuration file.

For CI 1.6.x you must hard code the application URL into the configuration file so. If this is your version you may need to upgrade or mod the app.

HTH :)

jim
  • 8,670
  • 15
  • 78
  • 149
  • It's definitely version 2. I appreciate the response. What makes this insecure as you have mentioned? What is it I'm trying to stop happening? – Joe W Oct 07 '11 at 11:30
  • 1
    Well, if you didn't put in a check other people could point their domains to your service. They could then show your app under their domain name.. Or maybe thats what you are looking for. I was under the impression you wanted that but would also like to validate the domains that show your app?? – jim Oct 07 '11 at 11:34
  • You assume correctly, I was just unsure as to what exactly the security issues were. – Joe W Oct 07 '11 at 16:45
  • There could be many more.. I'm not up to date on the latest domain/dns related exploits so no use there really, just giving my 2 cents? Are you going to try this? I can offer another domain if you want to test.. – jim Oct 07 '11 at 17:46