How to accomplish this > www.mysite.com/username/controller/function/id |
[eluser]JoostV[/eluser]
In config/routes.php, make a custom routing for every controller other than user. Code: $route['home/:any'] = "home"; Then, underneath those routing statements, make a route that will send all other uri's to controller users. Code: $route[':any'] = "users"; As long as users cannot choose a username like 'comment' or 'home', you'll be fine
[eluser]McNoggin[/eluser]
You could use mod_rewrite to do all the work for you. That way you wouldn't have to change CI at all.
[eluser]codeninja[/eluser]
McNoggin, can you tell how can we use mod_rewrite to accomplish that? i want to do something specific.. i want to create city specific portal output .. so write now its www.xyz.com, i want to be able to do city1.xyz.com, city2.xyz.com etc...
[eluser]drewbee[/eluser]
[quote author="McNoggin" date="1226064473"]You could use mod_rewrite to do all the work for you. That way you wouldn't have to change CI at all.[/quote] Exactly. While my regex skills are a bit one-off, you would do something like the following. Let's say we have the following: www.mysite.com/username/controller/function/id The problem is CI thinks username is the controller when it is not. Heres what I recomend. Identify the fact that it is a user somehow (by a ~ or some other symbol). So if we wanted to access username, it would be www.mysite.com/~username In the regex parse out the ~(username), (controller/function/id) now, when we are passing these values to the index.php, right now the CI htaccess file passes EVERYTHING. What I would do, is every function will have a second parameter. This is how we will pass the username to it. Slap the split regex back together: (controller/function/id)/(username) Now www.mysite.com/~username/controller/function/id is actually passing www.mysite.com/controller/function/id/username Then in our controller... Code: class Controller extends Controller www.mysite.com/~myTestUser/controller/function/id results in : myTestUser This symbol being used is near essential. That way, on any 'normal' page that isn't specific to a username, we can still use standard CI functionality. Current, the following is the part of the htaccess file that does your dirty work. Code: RewriteRule ^(.*)$ index.php/$1 [QSA,L] Code: RewriteRule ^~(.*)/(.*)$ index.php/$2/$1 [QSA,L] I hope this gets you the idea you were looking for. This, IMO, is by far the most elegant solution, and plus, no route/core changes
[eluser]McNoggin[/eluser]
Thanks for filling in the details drewbee. I knew it could be done but I haven't messed with mod_rewrite in so long I was scratching my head trying to remember how to create the rules.
[eluser]jadebot[/eluser]
Hey guys, I am going to hijack my own thread here (kinda). I have been using my hack here to move production along when it finally hit me: I can use virtual subdomains rather than "mysite.com/user". So ideally it will be user.mysite.com/controller/method. Yes I'm an idiot! So now after an hour of trying to learn regex I'll appeal to those better than me. The plan is to use mod rewrite to simply point any subdomain to the main site. Example: Code: user1.mysite.com/blah -> mysite.com/blah I can then extract the subdomain from fetching the URL (since the url will still be user1.mysite.com/blah ) and load the user session that way. If anyone can help me I would greatly appreciate it. I can drop someone $15(us) via paypal or tipjoy as a tip. So here is a conceptual approach to the rewrite rules: Code: IF URL contains subdomain Any help is appreciated. Regex is way over my head! |
Welcome Guest, Not a member yet? Register Sign In |