Little tutorial for creating pages with .html extension in CodeIgniter |
[eluser]Zorancho[/eluser]
If you want to have urls with .html extension with CI, you can achieve it in two ways. I will try to explain both of them. 1. .htaccess file This will rewrite everything in the first part of the url that's ending with .html and it doesn't contain / slash to pages controller and view action passing the link as parameter. www.site.com/some-page.html will be redirected to pages/view/some-page Code: <IfModule mod_rewrite.c> This will redirect www.site.com/product/some-product.html to products/view/some-product If you print out $this->uri->segment_array() it gives: Code: array( Code: <IfModule mod_rewrite.c> Open app application/config/routes.php. You can add your own urls here. This will redirect www.site.com/some-other-page.html to pages/view/some-other-page same like you would add it in your htaccess file. Code: $route['^([^\/]*).html$'] = 'pages/view/$1'; You can even add multiple rules if you are using multi language application: Code: $route['^en/([^\/]*).html$'] = 'pages/view/$1'; //English The routing of CI is very practical and nice, it works almost same like htaccess file. Please share if someone has other solution There is also $config['url_suffix'] = ""; it's in the application/config/config.php file on line 37, but not sure how it serves the urls.
[eluser]Eric Barnes[/eluser]
The $config[‘url_suffix’] = '.html'; would be the easiest method as CodeIgniter handles everything as normal but just adds the .html extension. I would try it first. |
Welcome Guest, Not a member yet? Register Sign In |