Codeigniter, domain to a certain area of the site - php

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.

Related

Angular routing under wordpress site

I have a WordPress site where one of the pages that WordPress serve is an SPA based on AngularJS. The Angular-app uses html5mode so that I can browse to http://localhost/79133/71 and I'm still showing index.html. Now I want to deploy this to my WordPress site so that one of the pages under WordPress (the main page) is my SPA. However, if I browse to http://example.com/79133/71 WordPress will try to find the page with the permalink 79133/71 and won't understand that the main page should be served. How can i configure WordPress so that these new "routes" will be pointing to the first page?
I'm not an expert on WordPress, but in order to get html5mode to work in angular:
Any route starting with /your_spa needs to serve the main page (index.html) of your app.
You must ensure that any resources referenced in your spa (for example, /assets/themes/theme.css) needs to point to the correct location, even if your location url is your_spa/your/spa/page. This means no relative paths unless you use the base tag.
Here's a tutorial on how to configure the router in wordpress. I don't use wordpress so I'm sorry that I
It seems like a lot of trouble, and I would just use the default hash routes if possible.
I had the same basic issue, and solved it. Your situation is slightly different but I think you need something like:
function spa_rewrite() {
add_rewrite_rule('79133/71', '/', 'top');
}
add_action('init', 'spa_rewrite');
In practise you'll need to use some regex to make this more flexible

Is creation of subdomain the only way?

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

Page forwarding with transfer of parameters called in URLs from one folder to another

In my wordpress page, links are addressed in the way:
www.mywebsite.com/blog/?page_id=1234
And each number gives a different page. I would like to have a forwarding mechanism that would forward a page in the form
www.mywebsite.com/mypage/?page_id=1234
when done in the folder "mypage", to the other folder "blog" as:
www.mywebsite.com/blog/?page_id=1234
with transferring each variable I have on the URL (in this case the only variable is page_id, and I would like to have all the variables forwarded to another page).
I'm pretty experienced in HTML and C/C++, but a beginner in PHP (though I've noticed that PHP is very similar to c in its logic, and I've done many changes in my Wordpress page based on my knowledge in C).
How can I do such a forwarding of code? Is it possible?
If there's any information missing, please let me know.
Thank you for any efforts.
This website gave a good tutorial on this. It took me 15 minutes to implement the solution.
http://html.net/tutorials/php/lesson10.php
SESSION if you want it to be specific for every user, POST if you dont want to change the url and the same for every user.
Im not really sure I understood your question.

Change what a link looks like with .htaccess

I have a Joomla based community site and with search engine friendly URLs activated in the backend my profiles are located under mysite.com/community/profile/user/"username"
I need the htaccess file to do nothing unless a URL containing "community/profile/user" is found. If that string is found then it should change the link to mysite.com/"username" but in reality be showing the page mysite.com/community/profile/user/"username"
I think this would be rewrite rule instead of redirect, but I barely know what I'm talking about.
Can someone please tell me what code I must place in my .htaccess file in order to change this? I believe .htacces would be the best way to do what I need, but if you have another idea I'm glad to hear it.
First be sure you understand .htaccess's role.
It is only read when an incomming request is made. So it will not change URLs generated by joomla.
You can however allow urls like mysite.com/eddie to actually pull content from mysite.com/blah/blah/eddie
http://httpd.apache.org/docs/current/rewrite/remapping.html
If you are looking to "train" your users, you can add a step before that to redirect the URL as well. This get's very tricky though as if you're not careful you can get caught in a loop.
user clicks mysite.com/blah/blah/eddie
apache redirects to mysite.com/eddie
(browsers makes second request, user sees URL change)
apache sees mysite.com/eddie and loads the underlying mysite.com/blah/blah/eddie
An easier solution might be to tweak the joomla community code to generate the short urls (mysite/eddie) and use apache to make a call direct to the plugin (mysite/components/communit/index.php?user=eddie

How can I do this with page redirection?

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.

Categories