1

I am developing a site on Codeigniter 2.0.2 . Its a site where companies/users can signup and create their own profile page, have their own custom url(like http://facebook.com/demouser), have their own feedback system, display their services.

This said, I have been successful in display the profile page in the following format

http://mainwebsite.com/company/profile/samplecompany This displays the home page for the company samplecompany , where company is the controller and profile is the method.

Now I have few questions,

  1. I guess it is possible to create to have/get http://mainwebsite.com/samplecompany using htaccess and a default controller. If anybody can help with the htaccess rule , that would be awesome. I am already using htacess to remove index.php from CI but could not get this working.

  2. There will be few other pages for the given user/company such as feedback, contact us, services etc. So the implementation links that come to my mind is of the form ` http://mainwebsite.com/company/profile/samplecompany/feedback or http://mainwebsite.com/samplecompany/feedback

http://mainwebsite.com/company/profile/samplecompany/services or http://mainwebsite.com/samplecompany/services

http://mainwebsite.com/company/profile/samplecompany/contactus or http://mainwebsite.com/samplecompany/contactus

wheresamplecompany` is the dynamic part Is it possible to create site links in the format?

  1. I understand using A record for a given domain, I can point a domain say, http://www.samplecompany.com to http://mainwebsite.com/company/profile/samplecompany so typing http://www.samplecompany.com he should be taken to http://mainwebsite.com/company/profile/samplecompany . If this is successfully implemented, will http://www.samplecompany.com/feedback http://www.samplecompany.com/services http://www.samplecompany.com/contactus

work correctly?

1
  • I need help with edit and formatting , I guesss! Commented May 25, 2011 at 19:06

2 Answers 2

4

I guess it is possible to create to have/get http://mainwebsite.com/samplecompany using htaccess and a default controller. If anybody can help with the htaccess rule , that would be awesome. I am already using htacess to remove index.php from CI but could not get this working. There will be few other pages for the given user/company such as feedback, contact us, services etc. So the implementation links that come to my mind is of the form ` http://mainwebsite.com/company/profile/samplecompany/feedback or http://mainwebsite.com/samplecompany/feedback

You can accomplish this using routes. For example, in your /config/routes.php file, put this:

$route['samplecompany'] = "company/profile/samplecompany";
$route['samplecompany/(:any)'] = "company/profiles/samplecompany/$1";

The first rule tells CodeIgniter that when someone accesses http://mainwebsite.com/samplecompany that it should process it as if the URL were "company/profile/samplecompany". The second rule captures anything that comes in the URI string after "samplecompany" and appends it onto the end.

However, if you have multiple companies(not just samplecompany), you're probably going to want to extend CI's router to suppor this unless you want to manually edit the config file each time a new company is added.

OK, you're definitely going to want to handle dynamic company names(as per your comment). This is a little trickier. I can't give you the full code, but I can point you in the right direction.

You'll want to extend CI's router and on an incoming request query the DB for the list of company names. If the URI segment matches a company name, you'll want to serve it up using your company/profile method. If it does not, you will ignore it and let CI handle it normally. Check out this post on this topic for more information: forum link.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the answer. Actually samplecompany is a dynamic value, I mean its a unique name chosen during registration. Its a unique word chosen by the user to build their url. So I guess, I wont be able to put that in routes.php file., because they will all be stored in the database along with the company's other information. I am looking forward to your opinion on the updated information.
Added a couple paragraphs at the end of my answer to give you some more info.
Thank you, for pointing me to the forum link, going to dig through it. I see its a concept around "Databased based routing in codeigniter" :)
1

Here's a great guide on how to achieve what you need: Codeigniter Vanity URL's.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.