Вопрос

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

Это было полезно?

Решение

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 :)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top