Sometimes we see some websites which are quite big. But we see .html at the end of their URL. Do you think it is possible for anybody to create large scale dynamic websites by using simple HTML only? In my opinion, it is such a big and time taking task to make a large scale website with HTML only. If you are developing a PHP powered website then using .html or .htm is not possible normally. Though, .php can be removed from its URL by using a few htaccess codes. Here I am going to tell you how to add .html suffix to the CodeIgniter website URLs. Along with I will also show how to add .php suffix to CodeIgniter website URLs. You can also add .htm/.jsp or any other extension to your CodeIgniter website URLs.
To add a suffix in CodeIgniter URL, firstly, you should be aware of CodeIgniter’s Directory structure. If not, this article on CodeIgniter Directory Structure Explanation is for you. So, assuming that you know CodeIgniter Directory structure well.
Add .html suffix in CodeIgniter
To add .html suffix in CodeIgniter, go to the application/config folder. Open config.php file present in that folder. This file is used to set up the configuration of your CodeIgniter website. There you will find the fourth option of $config array, i.e. ‘url_suffix’. This $config[‘url_suffix’] has a blank value which means there will not be any suffix append to the CodeIgniter generated URLs.
To add .html to Codeigniter URLs, assign ‘.html’ value to this index. Like, I am doing in the code given below.
$config['url_suffix'] = '.html';
That’s all. Now your website will have URLs mywebsite.com/login.html which was previously mywebsite.com/login/, as shown in the image below.
Similarly, we can add .php to the end of the URL.
How to .php suffix in CodeIgniter
Like in the process above, open the application/config folder. Access the config.php file residing in that folder. Find the $config[‘url_suffix’] option. Assign ‘.php’ in place of blank value to this index like I am doing in the example below
$config['url_suffix'] = '.php;
That’s all. Now your website will have URLs mywebsite.com/login.php which was previously like mywebsite.com/login/. Refer the image below for visible changes in URL.
In the same way, you can add any suffix like .jsp, .htm etc to your CodeIgniter website URLs.
You can download latest version of CodeIgniter from their official website.