Pass agrument to home page |
[eluser]thephpguy[/eluser]
So here is what i want to do, I am developing a small project, Code: http://abc.com/ what i want is if user enter Code: http://abc.com/username Code: 'username' This can be achieved By simply changing the url to http://abc.com/controller/index/username this will work but the url seems very clumsy its no longer pretty which i want. I tried using _remap but it doesnt works. its gives me 404 error i know its looking for a controller 'username' which doesnot exists. So what i want, is there any way by which we can ask CI to consider this kinds of url as special urls i mean we can route this urls to any specific controllers. I am not regex expert but i know this can also be done using routing using regex. If you can it will be very big help for me. Thanks in advance ;-)
[eluser]smilie[/eluser]
Look at routes.php. I still strugle with those myself, so can not give you any concrete answers ![]() Cheers, Smilie
[eluser]Cristian Gilè[/eluser]
Code: $route['(:any)'] = "controller/method/$1";
[eluser]thephpguy[/eluser]
[quote author="Cristian Gilè" date="1294272314"] Code: $route['(:any)'] = "controller/method/$1"; I tried but wont help, it will redirect all requests to controller/method which i dont want. Any other suggestion??? 8-/
[eluser]sean_THR[/eluser]
Replace "controller/method" with the actual name of the controller and method that you want to call.
[eluser]thephpguy[/eluser]
[quote author="sean_THR" date="1294315766"]Replace "controller/method" with the actual name of the controller and method that you want to call.[/quote] Yea but what to route?? Code: $route['(:any)']
[eluser]Atharva[/eluser]
Code: $route['^(?!controller1|controller2|controller3).*'] = "yourcontroller/yourfunction/"; What this will do is this will redirect domain.com/username to yourcontroller/yourfunction. It will check if the controller in the uri is NOT the one mentioned in the rule. So you can have a special controller only for handling the 'domain.com/username' link structure.
[eluser]thephpguy[/eluser]
[quote author="Atharva" date="1294316412"] Code: $route['^(?!controller1|controller2|controller3).*'] = "yourcontroller/yourfunction/"; What this will do is this will redirect domain.com/username to yourcontroller/yourfunction. It will check if the controller in the uri is NOT the one mentioned in the rule. So you can have a special controller only for handling the 'domain.com/username' link structure.[/quote] Hmmm will try that but dont you think it will be quite tedious to keep track of all controllers and add them up. Its good no doubt but how about this check the URL for ex: Code: http://abc.com/username Code: http://abc.com/ Code: '/' Code: mycontroller/myfunction/$1
[eluser]sean_THR[/eluser]
This is a pretty lazy untested regex: Code: ^(.+)\/(.+)$ So, in theory, http://www.abc.com/username will not produce a match, but http://www.abc.com/controller/method will as will http://www.abc.com/controller/method/paramater. Anyway, I think it should do what you need, but it may need work. Once again, I have not tested it.
[eluser]thephpguy[/eluser]
[quote author="sean_THR" date="1294319498"]This is a pretty lazy untested regex: Code: ^(.+)\/(.+)$ So, in theory, http://www.abc.com/username will not produce a match, but http://www.abc.com/controller/method will as will http://www.abc.com/controller/method/paramater. Anyway, I think it should do what you need, but it may need work. Once again, I have not tested it.[/quote] Excellent, but can you get something to do opposite, what i mean is any regex to match Code: http://www.abc.com/username Code: http://www.abc.com/controller/method And how do you use regex in routes?? i have been trying but cant get it working :-( |
Welcome Guest, Not a member yet? Register Sign In |