Dynamic Routes Rules |
[eluser]serhat[/eluser]
In my new cms i have page system like domain.com/contact domain.com/.... i'm defining them for per page like this $route['contact'] = "blog/page/contact"; Is it possible to do this dynamic For example i added a page named ci. I don't want to write this to route by hand everytime. $route['ci'] = "blog/page/ci"; In routes file can it read from mysql and with if condition it put to route file auotmaticly? Thanks for help
[eluser]bigtony[/eluser]
You could try this: Code: $route['(:any)'] = "blog/page/$1";
[eluser]serhat[/eluser]
I know but my (:any) is already filled with something else so i have to use it with another way
[eluser]Dam1an[/eluser]
What does :any to map anyway? You could always make that function do a lookup for segment(3) as a slug in the CMS, and if that returns no results, carry on with whatever that function was doing before, otherwise, do the CMS thing
[eluser]doob[/eluser]
Code: $pages = array('ci', 'home', 'foo', 'bar'); //get this from your DB Maybe?
[eluser]serhat[/eluser]
In :any i have posts of my website. so when i want to use it as page. I points another place. I don't want url like asd.com/page/my-page So i think the best solution(if it's working on routes.php) grabbing them from database. Else I think i can check whether that uri->segment is page or normal post That's another way. [quote author="Dam1an" date="1249936292"]What does :any to map anyway? You could always make that function do a lookup for segment(3) as a slug in the CMS, and if that returns no results, carry on with whatever that function was doing before, otherwise, do the CMS thing[/quote]
[eluser]Jondolar[/eluser]
Create a different method in your blog controller. Use the "page" method/function for your "pages". Use the other function (such as "posts") for your "normal posts". Now, in the posts() function you can look at segment 3 of the uri to determine which post to use. You won't need to use any custom routes to do it this way.
[eluser]Kepler[/eluser]
If I am understanding correctly you want normal page URLs to look like: www.example.com/contact And blog posts to look like: www.example.com/blog/post-name I would use mod_rewrite (if you are running under apache) to rewrite the URLS for you. In your .htaccess file: Code: <IfModule mod_rewrite.c> Now www.example.com/contact => www.example.com/blog/page/contact and www.example.com/blog/post-name => www.example.com/blog/post/post-name Hopefully I understood your issue correctly.
[eluser]Donny Kurnia[/eluser]
Hi, I might have same problems and wonder if this can be solved using mod_rewrite. I want username in the first segment, like this: http://site/username But I also need to access existing controller: http://site/admin http://site/welcome http://site/u/get_by_name/username <-- this is the real handler for case where username as first segment above My question is, how I can write the mod_rewrite rule? I tried using RewriteCond, but ended all url redirected to: http://site/u/get_by_name/ So I cannot access: http://site/admin Please help.
[eluser]Donny Kurnia[/eluser]
I'd like to answer my own question. I just have it resolved. This is the content of my .htaccess file Code: <IfModule mod_rewrite.c> With this setup, if I go to: http://site/username the page I see actually will be: http://site/u/get_by_name/username I can still go to other controller page, such as: http://site/admin/index I hope this will help other that have same problems. Thanks. |
Welcome Guest, Not a member yet? Register Sign In |