Usernames as subdomains and a root website |
[eluser]whizzer[/eluser]
Hello forum, I'm trying to make a website like blogger where every registration would be is subdomain-style. I used that method and evrything works. But now i have a problem. I need to accomplish several things: 1. Check for a valid username. Before the controller with the user template, content and etc is loaded I need to make sure that the username is valid. For example bad.username.blogger.com is not valid and should lead to the 404 page. Also if there isn't a registered user with that username. 2. Load the default website. When blogger.com (just an example url) is opened, there is no username (hence the username is an empty string '') and I should load the default website. 3. Do 1 and 2 before the main controller is loaded, so when I load it for the first time I will know what the username is (or a blank one for the root website) and load the corresponding theme, content, etc. I'm also accepting ideas for a directory structure. There will be the templates for my root website as well as the templates for my users blogs. Thank you. ![]()
[eluser]pickupman[/eluser]
Check out [url="http://ellislab.com/codeigniter/user-guide/general/hooks.html"]hooks[/url]. The allow you to execute code before certain parts are loaded in CI.
[eluser]whizzer[/eluser]
I know about the hooks. But my main question was how to load two completely different websites - my root website (with templates and with its own functionality) and my blog urls (hence the user's blogs)?
[eluser]BrianL[/eluser]
Subdomains are handled by the web server, not CI. If you're using cPanel handle subdomain redirection through subsites, not subdomain, as the cPanel meaning of subdomain is different than the DNS meaning of subdomain. If not, hosting two totally different websites with the same IP is called virtual hosting and the method is specific to your webserver. Apache with Debian is particularly elegant, but all major webservers support virtual hosting.
[eluser]whizzer[/eluser]
I guess I'm know explaining myself properly. I am redirecting all my subdomain requests (ex. test.site.com, username1.site.com, user.name.test.site.com) to my root website - site.com. There I have an CI installation. In a hook I validate whehter test, username1, user.name.test are registered users. If not or if site.com is accessed I want to show my main website. However, if there is a registered user "username1" I want to show his blog. Here's how I think it should work: Controller "site" with method "index" for my main website. It will be set as a default controller, so accessing site.com will show my site. Controller "blog" for my user's blogs. However here I have a problem. If the user accesses username1.site.com I will know (using my hook) that he is a valid user. But how will I load the contents of the blog without adding class and a method name. Ex: username1.site.com /blog/index will work, since in the blog controller I will know the username (username1) and I will be able to load the contents. But I don't want that /blog/ part of the url. Any ideas?
[eluser]Udi[/eluser]
I did something like this... like "mini-site" under your website... Google "Wild Card subdomain".. you need to add new DNS record in your server and modify .htaccess file a little bit..
[eluser]whizzer[/eluser]
Please don't reply if you haven't read the posts...I explained that I did the wildcard thing and my site works properly. The problem is with my user's blogs and the lack of class/method/ in the URL. ![]()
[eluser]Udi[/eluser]
Lack of class/method where? when u first enter user.subdomain.com, the .htaccess file activates the proper class/method.. What is the base url in your config.php?
[eluser]whizzer[/eluser]
When username1.site.com is reached.If using htaccess I redirect it to site.com/blog/view/username1 it will be ok. But if the user wants to post a message and clicks on username1.site.com/blog/post/ how do I get the username?
[eluser]Udi[/eluser]
Code: $config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/"; YOU ALWAYS LINK TO username.domain.com, so its always: username.domain.com/post/ OR username.domain.com/view/ you just need to identify the username in your app.. I do something like this: Code: // $subdomain going to store the username... you got the idea? |
Welcome Guest, Not a member yet? Register Sign In |