Question: I'm trying to edit my .httaccess configuration. I want redirect everythink to https, but if I try this, what I found on stackoverflow:

```
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

```

It wont redirect.

Now my .htaccess looks like:

```
RewriteEngine On

# ignore all existing files and directories for rewriting     
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([\d+^/]*)$ /index.php?id=$1 [QSA,L]
RewriteRule ^([\w+^/]*)$ /index.php?name=$1 [QSA,L]

```

Rewrite rules like: 

```
^([\d+^/]*)$ /index.php?id=$1 [QSA,L] 

```

working well if I want 

* www.mydomain.com/523

it is like 

* www.mydomain.com/index.php?id=523

So how can I append my code to redirect from 
http:// to https:// and my older rewrite rules will still work?

Answer: 
Update foreach loop only 

```html
$html = '';
foreach($get_data->result() as $data):
            $sport = str_replace($keyword, "<b>" . $keyword . "</b>" , $data->cat_name);
            $html  .= '<li onclick="set_item(\''.str_replace("'", "\'", $data->cat_name).'\')">';
            $html .= $sport;
            $html .= "</li>";

        endforeach;
return $html;
```
After return type everything would be vanish. You write return inside foreach loop. Loop iterate only one time and return.

Need to concatenate start tag of `li` with `$html` 

also return outside of foreach loop as 

```
foreach($get_data->result() as $data):
            $sport = str_replace($keyword, "<b>" . $keyword . "</b>" , $data->cat_name);
            $html  .= '<li onclick="set_item(\''.str_replace("'", "\'", $data->cat_name).'\')">';
            $html .= $sport;
            $html .= "</li>";

        endforeach;

return $html;// return here

```

Use `num_rows();` to check query return result or not as

```
$num = $get_data->num_rows();

if($num>0)
{

 foreach($get_data->result() as $data):
                $sport = str_replace($keyword, "<b>" . $keyword . "</b>" , $data->cat_name);
                $html  .= '<li onclick="set_item(\''.str_replace("'", "\'", $data->cat_name).'\')">';
                $html .= $sport;
                $html .= "</li>";

            endforeach;
}else{
     $html="<li>NO result found</li>";
}

    return $html;// return here

```