Development Mode
Firstly we will look into configuring the development mode for the system. You can configure it in
index.php
file under Source Files. By default environment is set as development.
define('ENVIRONMENT', 'development');
When the system is implemented it can be changed into production environment. In production environment error reporting is disabled. Usually in production servers errors are disabled by default. But this configuration is worth to know.
define('ENVIRONMENT', 'production');
Mod rewriting
Mod rewriting is simply about redirecting the user to another file location without user realizing it. Advantage of it is that user would not be requested to remember hideous lengthy URLs. Instead user can use a shorter form which will be redirected to that lengthy URL. User may enterwww.abc.com/welcome
which really means www.abc.com/index.php/welcome
. In mod rewriting, URL is rewritten at server level.
Mod rewriting can be done by defining mod rewriting rules in .htaccess file. These rules can be easily understood and written if you know regular expressions already. First a file should be created and named as
.htaccess
under Source Files. .htaccess file contains directives for Apache. Any directive in .htaccess file will be applied to the same directory it is saved and any sub directory. Thus these Mod Rewriting rules are written and saved in .htaccess file.
For this article series based on CodeIgniter I use below Mod Rewriting in my .htaccess file. If you wish to understand more you can read this article and many other articles around Internet.
In this code "RewriteBase" refers to the root folder of the project. You should change the RewriteBase according to your root folder name.
RewriteEngine On
RewriteBase /CodeIgniterTest
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
After that open application/config/config.php
which is under Source Files. Change
$config['index_page'] = 'index.php';
$config['index_page'] = '';
To make this mod rewriting work, you have to turn on mod_rewrite module in Apache. To check the status of mod_rewrite module either you can follow given phpinfo() link in XAMPP or WAMP server. Otherwise write this simple coding
<?php phpinfo(); ?>
in a php file, save it in your apache root folder and view it through your web browser. If mod_rewrite module is enabled you will see httpd.conf
file of Apache server. You just have to remove the "#" in front of the
LoadModule rewrite_module modules/mod_rewrite.so
save the file and restart the server. Your Mod Rewrite rules should be working now.If you are working in a Linux environment you can simply enable the mod_rewrite module by using the following command
sudo a2enmod rewrite
Then restart the apache server. Your Mod Rewrite rules should be working now.
No comments:
Post a Comment