Found this random quote in Facebook and fill to preserve it to keep me motivating toward the science and prosperity and keep me away from superstation.

“I have noticed even people who claim everything is predestined, and that we can do nothing to change it, look before they cross the road.” – Stephen Hawking

stephen hawking quote
Disclaimer: I didn’t search for any direct reference for this quote, but I like the saying even if this is not said by Stephen Hawking

How to remove index.php from url using .htaccess

Remove index.php from URL to avoid duplicate content issue

You want to redirect example.com/index.php/welcome to example.com/welcome ? Are you tired of finding proper solution about how to Remove index.php from URL to avoid duplicate content issue  or to redirect index.php to actual URL without index.php? You are in the right place mate!

I am a PHP based developer and most of time I use CodeIgniter as my php framework. Those who use CodeIgniter and obviously other framework, we use some technique to remove index.php  from our URL to make it more clean, short , Web 2.0 friendly and penitentially to avoid duplicate content issue in Google Web Master. In CodeIgniter, we do it in two steps:

How to remove index.php from URL in CodeIgniter

Step 1: We update application/config/config.php file

//keep the variable empty to remove index.php after your domain name
$config['index_page'] = '';

Step 2: We update our .htaccess file as

RewriteEngine on
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Cool! That removes index.php from our URL.. thats really great… but wait! What if anyone put index.php in your url like http://www.example.com/index.php/welcome/ ? Yes that is still accessible and duplicate content of http://www.example.com/welcome/ .

How I removed the index.php from url

I had the same problem in one of my project and needed to solve it. I spend hours to solve it but couldn’t found any solution until I found this post htaccess remove index.php from url in stackoverflow. I just put following lines in my .htaccess file

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

and my problem solved.

Now if you intentionally write http://www.example.com/index.php/welcome/ in your address bar, it will be converted to http://www.example.com/welcome/ . I guess your problem is solved to.

Let me know if it helps you

 

codeigniter

CodeIgniter .htaccess and index.php issues – Solution

CodeIgniter index.php and .htaccess issue ruined my last night. I’ve solved this simple issue many times before but not any solution was working that time.

Few days before today, I was working in a client project which I’ve been demonstrating to my client from my personal demo server which is a HostGator Baby Plan Hosting.  The site was running fine in my local pc (Win7 running XAMPP 1.7.7 running the site in VirtualHost) and in my demo server but when I push the code in client’s staging server (Rackspace Cloud server with CentOS 6.4, Apache2 ) , I was getting a 404 Page Not Found error message. First I checked my .htaccess file and it was same as my demo server, same as my local pc which is

RewriteEngine on
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

In my config.php file, I set

$config['base_url'] = 'http://staging.example.com/';
$config['index_page'] = '';

but nothing was working. I tried every solution I used before and I found over Internet but couldn’t find any perfect solution to solve my problem.

Everything seems fine and I was getting frustrated. Finally one solution I found where it says, I’ve to edit my httpd.conf file

httpd.conf File location in CentOS 6.4

httpd.conf File location in CentOS 6.4

and change AllowOverride None to AllowOverride All and saintly this solution worked Perfectly.

VirtualHost settings

VirtualHost settings to remove index.php file in CentOS 6.4

What Problem this was?

With my little understanding on server things, I understand that though we set the rule in .hetaccess to remove the index.php file, it was not fully permitted by staging.conf file. When working in Windows with XAMPP, this file location is in your drive:\xampp\apache\conf\extra\httpd-vhosts.conf

If you still reading, let me know if the solution work for you or If I need to update this posting in anywhere. I am open to creative suggestions :)

How to get value of Array in foreach loop

While working on my CodeIgniter based Open Source Project Management tool “Koronio”, suddenly I needed create a loop to generate a Dropdown element with array key as option value. This is very simple trick, provably everyone knows it, though I felt to share it.

Lets say, we have a php array named $priority which has 5 items.

$priority=array('Low','Normal Low',"Normal",'Normal High','High');

We want to show this items in a Select Item with Array value as option name and Array key as option value.

foreach($priority as $key=> $val)
{
echo '<option value="'.$key.'">'.$val.'</option>';
}

Thats It! You’ll have a dropdown list with the Priority list and value as option value.

Check Password Strength with jQuery Plugin

I was developing an Web Application recently. Like all other web app, this has user registration process and  password field for user. My client wanted to use a Password Strength Meter to indicate user how strong is his/her password. Well that’s a nice and must have feature for most of apps now.

I been searching for a jQuery plugin for this password strength feature and found a lots of plugins available for use. Well, I can’t use a lot of plugins but just one and I had to pick only one and I picked a simple one.

I choose this jQuery Password Strength Plugin from many. Reason for this choosing is,

  • easy to use
  • small but good documentation
  • little but necessary customization options

How to use Query Password Strength Plugin

Requirements

  • jQuery
  • jquery.passstrength.js or jquery.passstrength.min.js

Download jquery.passstrength.js or jquery.passstrength.min.js from original site and keep them in your root folder or any folder you want (figure1)

Files for password strength meeter

Figure 1

Assume following is your html for password field in index.html (figure2)

<div id="passwordmeter">
  <label for="password">Password</label>
  <input type="password" id="password"/>
</div>
password field

Figure 2

Now add the following javascript at bottom of your page (before </body>).

<script type="application/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="application/javascript" src="passstrength.min.js"></script>
<script type="application/javascript">
jQuery(document).ready(function()
{
  jQuery('#password').passStrengthify();
});
</script>

Well, that’s it. This should be working like this now.

Password Strength Meeter

Password Strength Meeter

See the demo here. Download Demo