Friday, January 7, 2011

Search (seo) Friendly Url - apache mod_rewrite

For rewriting the URL, you should create a .htaccess file in the root folder of your web directory

at the beginning of url rewritting

These first two lines required whenever you use mod_rewrite  (the part of Apache that does all this magic) will always be the same:you only need to do this once per .htaccess file:

Options +FollowSymlinks 
RewriteEngine on

 before any ReWrite rules. note: +FollowSymLinks must be enabled ( RewriteEngine on ) for any rules to work, this is a security requirement of the rewrite engine.

for an example 
the Dynamic url is:  http://localhost/mathu/index.php?view=categorise
 Create file called .htaccess in the 'localhost/mathu' directory. Place the following mod_rewrite code in it.

Options +FollowSymLinks
RewriteEngine on
RewriteRule index/view/(.*)/ index.php?view=$1
RewriteRule index/view/(.*) index.php?view=$1 

After that, the generated seo friendly  Url look like this:
http://localhost/mathu/index/view/categorise/ 

 Another Example
http://localhost/mathu/index.php?view=categorise&category_name=abc
mod_rewrite code:

Options +FollowSymLinks
RewriteEngine on
RewriteRule index/view/(.*)/category_name/(.*)/ index.php?view=$1&category_name=$2
RewriteRule index/view/(.*)/category_name/(.*) index.php?view=$1&category_name=$2               
            

After that, the generated seo friendly  Url look like this:
 http://localhost/mathu/index/view/categorise/category_name/abc/ 

Sunday, January 2, 2011

JavaScript getElementById - example

getElementById -JavaScript DOM
 
var element = document.getElementById('idex');
 <div id="idex">
somthing here 
</div>
 
Another Example  
<script>
var ids=new Array('a1','a2','a3','a4');

function switchid(id){  
    hideallids();
    showdiv(id);
}

function hideallids(){
    for (var i=0;i<ids.length;i++){
        hidediv(ids[i]);
    }        
}

function hidediv(id) {
    if (document.getElementById) {
        document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) {
            document.id.display = 'none';
        }
        else {
            document.all.id.style.display = 'none';
        }
    }
}

function showdiv(id) {
        
    if (document.getElementById) {
        document.getElementById(id).style.display = 'block';
      
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'block';
        }
        else { // IE 4
            document.all.id.style.display = 'block';
        }
    }
}
</script>
here you have to ' id'
<a href="javascript:switchid('a1');" >div1</a><br />
<a href="javascript:switchid('a2');" >div2</a><br />
<a href="javascript:switchid('a3');" >div3</a><br />
<a href="javascript:switchid('a4');" >div4</a><br />
//div element with 'id'
    <div id='a1' style="display:none;">
              <ul>
                <li><a href=""> div1</a></li>
                <li><a href=""> div1</a></li>
                <li><a href="">div1</a></li>
                <li>SEO</li>
              </ul>
            </div>
            <div id='a2' style="display:none;">
              <ul>
                <li>div2</li>
                <li>div2</li>
                <li>div2</li>
                <li>div2</li>
                <li>div2</li>

              </ul>
            </div>
            <div id='a3' style="display:none;">
              <ul>

                <li>div3</li>
                <li>div3</li>
                <li>div3</li>
              </ul>
            </div>
            <div id='a4' style="display:none;">
              <ul>
                <li>div4</li>
                <li>div4</li>
              </ul>
            </div>

Saturday, January 1, 2011

PHP Redirect Problem

  header() is used to send a raw HTTP header.

  header( ‘Location: http://www.yourdomain.com/new_page.html’ ) ;

This function must be called before any actual output is sent unless you will get the following error:

    Warning: Cannot modify header information – headers already sent by

Or you can use ob_start() and ob_flush() function to avoid this problem by buffering the output.

    ob_start();
    echo “Test”;
    header( ‘Location: http://www.yourdomain.com/new_page.html’ ) ;
    ob_flush();


Using JavaScript

<script type="text/javascript">
window.location = "http://www.google.com/"
</script>