Im using CodeIgniter and I want to create a site in which many (about a thousand) users can register and do things.
Each user will have their own gallery, an about page etc.
What I want to achieve is that as the user login using password the url should show
user_name.domain.com
Do I really need to create subdomain for each user to achieve this
(The folder structure doesn't really made for the subdomain way and I am halfway through the project.So i would really appreciate other alternative (s,(if any))
Or
Can I achieve the same using htaccess rewrite url rule?
As PeeHaa pointed out you should use wildcards.
There's another stackoverflow thread covering the problem: codeigniter multiple applications, with wild card sub domains, mod_rewrite remapping sub domains to .php
Related
I need to create an application through which I can generate different sites. All these sites will have the same layout but each one will have different contents (texts, images, colors, etc).
The hard part is that these sites should be able to be accessed through different urls.
Let me give an example:
I log into the application from there I create a new site with the name FooBar and it may be accessed through the http://foobar.com url.
The same if I want a site http://foobaz.com. All sites may be generated and managed from the same administrator.
I have read about Wordpress multisite and I think maybe it could help me. If its not possible via Wordpress I can make it with some web framework like Laravel.
The main problem I cant figure out is how to map the domains with each site generated.
I think the right way to do this is to point all the domains to the same laravel app+routes so then in the controllers you can do the check of the domain the user is currently visiting and get the images and texts accordingly the domain from the DB.
In other words, make the logics on the controllers/helper level.
I'm building some kind of social-network site using PHP and mysql (and quite new to web development..). I want user profiles to be accessible trough the URL address as "http://www.example.com/username".
It is also very important to me that each profile page will be indexed by search engines.
How do I do this?
You need to use .htaccess - mod_rewrite to be more specific
You can find many resources online for this.
I have a revision website, it has stuff for multiple school subjects. I am starting to develop subject pages, these will have stuff only for that subject. e.g. a physics page
Anyway, what I am trying to do is let people type in www.myWebsite.com/history or www.myWebsite.com/ict - or what ever. And them get redirected to the appropriate page.
From that it sounds really simple, I would just put a file called history.php in my public_html home directory, right?
But my home directory is super organised, with everything in nice sub folders. I want to but all the subject pages in a sub folder called 'subjects' (imaginative name :p ).
How can I put these pages in the sub folder, yet still let the user access them from the URL examples above?
A great way to do this is to use a Front Controller. You can re-route all requests to one file (typically index.php) via htaccess and then from there grab the URI (the /itc, /history etc.) and use it to direct the request to the appropriate script.
Check this out, should get you started.
http://www.technotaste.com/blog/simple-php-front-controller/
Once you figure that out, you will want to compare the differences between dynamic and static invocation. Cheers.
you've got to do a url rewrite for the same. google out mod_rewrite and you'll get the examples.
If you are running under Apache, mod_rewrite is probably the most direct approach to accomplishing this.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Basically create a .htaccess file in the root that maps the URI segment to the appropriate php file in your 'subjects' directory.
I think this is a case where you could use mod_rewrite, so the web server you're using will redirect the user to the appropiate directory. You can either keep the rewrite list manually or dynamically using regexes.
How someone implement personalized URLs in a website?
For example http://www.facebook.com/john
or
For example http://www.facebook.com/john.smith
Having in mind that the users choose their names (which will be unique and can not change once chosen).
Platform is Apache, PHP, Mysql
Thank you
Using mod_rewrite to redirect traffic to a different path which handles the routing.
If you look at many of the popular PHP frameworks they suggest using a provided .htaccess file which forwards all requests to index.php and from their include their own routing class/script
As part of the routing, you could check if the path matches an existing user, and then make the request display that users page.
You'd use mod_rewrite to rewrite all incoming requests to something like http://example.com/index.php?q={request}. Then you can grab $_GET['q'] in PHP and do whatever you want with it. If it looks like a username, display the user's profile page, if it looks like the name of another page, include that page.
I'm not a very experienced programmer, and am using CodeIgniter for second time.
Suppose I have www.domain1.com. So I will have, say 3 controllers /area1, /area2, /area3. Users can access them as www.domain1.com/area1 etc. if I set the base URL as www.domain1.com. But my problem is, the client wants a certain area of the web, say area2, working as a microsite, in its own domain, so he wants to access area2 with www.domain2.com.
I don't know how to get this working with CodeIgniter. Suppose he registers www.domain2.com and set it pointing to the same DNS, server etc. How can I get CodeIgnitor to execute the controller area2 when the URL www.domain2.com is accessed?
Maybe changing $config['base-url']? Routing? .htaccess? Please, if you have solved this, examples of code involved would be greatly appreciated.
Edit: I will put example of the site I want to get.
I have one normal installation of CodeIgniter (external host, I can't access httpd.conf) It is on one machine, and the root of the site should be accessed by www.domain1.com
All domain are outside registered to. So I have the home controller, which shows me the main page view. And suppose the site have 3 areas /area1, /area2 /area3, with their correspondent controllers, showing these areas views.
My client want to emphasize one of the areas, the one that controller /area2 shows, and he want use a different domain for that area, www.domain2.com
What can I do so that when the user browse to www.domain2.com, CI redirects them to www.domain1.com/area2? Could I, for example, modify $config['base_url'] according the received URL, or is that impossible? Do I need to modify the .htaccess file?
After a lot of searching, I found a solution that seems to work, very easy to be honest:
Modify routes.php:
if ($_SERVER['HTTP_HOST']=="www.domain2.com") {
$route['default_controller'] = "area2";
}
No need for mod rewrite.
Here's a helpful link....
http://www.askaboutphp.com/88/codeigniter-setting-up-multiple-sites-on-one-install.html
Never actually done this myself, but this seems to be the way to go about it without having two ci installs. Good luck.
you definitely need to go the mod_rewrite way
the first solution that comes to my mind is to use Apache mod_rewrite, but as far as I know that would work only for internal redirects (i.e. resources residing on the same server/domain).
What about using an iframe? You could set up domain2.com home page with a full-page iframe that takes it's content from domain1.com/area2.