Saturday, May 12, 2012

Create your own CMS-Part 13

Now look at the two url given below
  • http://localhost/stupid/index.php?module=blogs&sub=editblog&action=save
  • http://localhost/stupid/blogs/editblog/save
The second url looks more readable and pretty.We can achieve this by url rewriting using htaccess or using php.In our cms we will be using htaccess.Also we will deny access for direct viewing of files in htaccess file.All the files can only be viewed through index.php or index1.php and soon....
  • Create a file in the root directory of your website (in our case 'stupid' directory)
  • Name it as '.htaccess'.Edit the file using notepad.
<FilesMatch "\.php$">   
 Order Allow,Deny  
 Deny from all
</FilesMatch>
<FilesMatch "index[0-9]?\.php$">  
 Order Allow,Deny   
 Allow from all
</FilesMatch>
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\=([a-zA-Z0-9_-]+)$ index.php?module=$1&sub=$2&action=$3&$4=$5
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?module=$1&sub=$2&action=$3
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)\=([a-zA-Z0-9_-]+)$ index.php?module=$1&sub=$2&$3=$4
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ index.php?module=$1&sub=$2
RewriteRule ^action\=([A-Za-z0-9\_\-\/]+)$ index.php?u_action=$1
RewriteRule ^([A-Za-z0-9\_\-\/]+)/$ index.php?module=$1
In order to distinguish the action parameter within a module from user actions like login,register etc,the url variable 'action' previously used in actions.php in actions folder will be replaced by 'u_action'.
So kindly replace the first 6 lines in actions.php with the following lines.
global $user;
if(isset($_GET['u_action']))
{
$action=$_GET['u_action'];
switch($action)
Now you can set the action of login form as
<?=BASE?>/action=login
So we are done with url rewriting.In the next post we will be creating a blog module.

2 comments:

  1. Hello AZYCRAZE! In how many parts is this turorial will be ended?

    Thanks!!!

    ReplyDelete
  2. Just few more

    creating a blog module,
    creating an admin interface.

    Suggestions for enhancing site look,security,etc.

    ReplyDelete