Logo Background RSS
  • Useful url rewriting using .htaccess
    By admin on February 4th, 2009 | 5 Comments5 Comments Comments

    If you are looking for the examples of URL rewriting then this post might be useful for you. In this post, I’ve given five useful examples of URL rewriting using .htacess. If you don’t know something about url rewriting then please check my older post about url rewriting using .htaccess.

    Now let’s look at the examples

    1)Rewriting product.php?id=12 to product-12.html

    It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.

    RewriteEngine on
    RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1

    2) Rewriting product.php?id=12 to product/ipod-nano/12.html

    SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.

    RewriteEngine on
    RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2

    3) Redirecting non www URL to www URL

    If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
    RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]

    4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz

    Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.

    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
    RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1

    5) Redirecting the domain to a new subfolder of inside public_html.

    Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside “new” folder.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.test\.com$
    RewriteCond %{REQUEST_URI} !^/new/
    RewriteRule (.*) /new/$1

    So guys enjoy with .htaccess :)

  • check ram size in Linux
    By admin on February 4th, 2009 | No Comments Comments

    you can use this command to find the ram size in your linux machine

    free

    Mem is Ram size in bytes. Use -m option for output in MB.
    SWAP is the size of SWAP partition.

    free -m

    Looks like you’re using up a lot of memory. Top displays your memory usage a little better as far as the “easy to read” factor goes.

    top

  • Install mod_limitipconn For Apache
    By admin on February 2nd, 2009 | No Comments Comments

    Installing mod_limitipconn.c :o

    This is the distribution page for the Apache module mod_limitipconn.c, which
    allows web server administrators to limit the number of simultaneous
    downloads permitted from a single IP address.

    Why did I write this module? Well, I run an mp3 server which since its
    inception was being constantly hosed by people who were trying to download
    dozens of files at once. For months I scoured the Internet looking for a
    code snippet that would solve this problem. The closest thing I found was this
    patch against an old version of Apache, and it didn’t run properly on my Linux box
    (that was back then; nowadays, the patch doesn’t even apply cleanly to the
    Apache source tree).

    Finally I gave up and decided to write something to do the job myself, and
    here’s the result.
    =================
    Log into ssh

    (Apache 1.3.x) -
    cd /usr/src
    http://dominia.org/djao/limit/mod_limitipconn-0.04.tar.gz
    tar xzvf mod_limitipconn-0.04.tar.gz
    cd mod_limitipconn-0.04

    (Apache 2.0.x)
    cd /usr/src
    http://dominia.org/djao/limit/mod_limitipconn-0.22.tar.gz
    tar xzvf mod_limitipconn-0.22.tar.gz
    cd mod_limitipconn-0.22

    pico Makefile
    find the line that reads APXS=apxs
    change that to
    APXS=/usr/local/apache/bin/apxs

    press cntrl O to save
    then cntrl X

    // if your locations to apxs is different
    locate apxs and copy the path
    then paste that in
    //

    make
    make install

    service httpd restart

    pico -w /etc/httpd/conf/httpd.conf

    locate ExtendedStatus
    Make sure ExtendedStatus is on and without the comment at the start

    and add this line to every virtual directory you want to limit
    or add it once to the main directory to limit all

    MaxConnPerIP 3
    # exempting images from the connection limit is often a good
    # idea if your web page has lots of inline images, since these
    # pages often generate a flurry of concurrent image requests
    NoIPLimit image/*

    MaxConnPerIP 1
    # In this case, all MIME types other than audio/mpeg and video*
    # are exempt from the limit check
    OnlyIPLimit audio/mpeg video

    press cntrl O to save
    then cntrl X
    then service

    httpd restart
    :D When i try it i have limit /download location and works really good. so dude enjoy :)

  • IP script php
    By sps on February 2nd, 2009 | No Comments Comments

    Hi this is a script to show your ip address

    <?php
    $ip = getenv(“REMOTE_ADDR”) ;
    Echo “Your IP is ” . $ip;
    ?>

    and save it with any name like file.php

  • PHP Spam Injection Protect it with Apache ModSecurity
    By vinod on February 2nd, 2009 | No Comments Comments
    From my old experience with my server From time to time we work with clients who would like to upgrade their web sites. Often their site is composed of various one-off applications — typically PHP-based — that someone built for them. More often than not, these applications were not developed with security in mind.
    Our first reaction is to pull the plug, analyze, and rebuild a secure and scalable solution. But pulling the plug is usually not an option. If a company relies on an application for leads or sales, they probably can’t afford to shut it down for any length of time. Under these circumstances, triage is usually the best one can hope for.
    Fortunately, there are a few things one can do to stem the bleeding. One of the more common problems with PHP-based applications is that they can allow the injection of malicious content, such as SQL or email spam. In some cases we find that over 95% of a client’s ISP traffic is coming from spam injection. The solution? Grab an industrial size helping of Apache mod_security.
    What is it? From the ModSecurity home page:
    ModSecurityTM is an open source intrusion detection and prevention engine for web applications (or a web application firewall). Operating as an Apache Web server module or standalone, the purpose of ModSecurity is to increase web application security, protecting web applications from known and unknown attacks.
    Essentially, it inspects web traffic passing through the web server for suspicious content as well as attempts to trigger buffer overflows, etc. When it finds such content, it can stop the traffic and/or log the incident.
    To put mod_security to work for you, first, download and unpack the tarball, build and install the DSO, and update Apache’s httpd.conf file.
    cd /usr/local; tar xzf /root/modsecurity-apache-1.9.4.tar.gz
    cd /usr/local/modsecurity-apache-1.9.4/apache2
    /usr/local/apache2/bin/apxs -cia mod_security.c
    Paste the ModSecurity minimal recommended filtering rules into your httpd.conf file.  Here are the first few lines from from the online manual’s Appendix A: Recommended Configuration:
    # Turn ModSecurity On
    SecFilterEngine On
    # Reject requests with status 403
    SecFilterDefaultAction “deny,log,status:403″
    # Some sane defaults
    SecFilterScanPOST On
    SecFilterCheckURLEncoding On
    SecFilterCheckUnicodeEncoding Off
    If you’d just like to see if someone is trying to exploit your site, you can set up ModSecurity to simply audit your traffic.  The lines
    # Log rule violations, but allow the requests
    SecFilterDefaultAction “log,pass”
    will do that for you.  However, please note that if you want to merely log rule violations without denying the traffic, you must not include any implicit validations (URL encoding validation, Unicode  encoding validation, cookie format validation, and byte range  restrictions) in your rules.When you are satisfied with your rules, you can deny the traffic by changing the default action to this:
    # Deny requests and log with status 403
    SecFilterDefaultAction “deny,log,status:403″
    Once you’ve got a bunch of traffic in your audit log, you can grep through it to see if you’ve got visitors with bad intentions:
    grep -i ‘to|bcc|cc’ audit_log | less
    or
    grep -i ‘to|bcc|cc’ audit_log | wc -l
    You may find lots of suspicious lines. In fact, you may find that some spammers are including portions of books, stories, or other nonsense, presumably to get past the final recipients’ Bayesian spam filters.
    To block a common PHP mail injection exploit, add a rule like this to your httpd.conf file in the ModSecurity section:
    # necessary to stop spammers doing mail injection into PHP mail forms!!!
    SecFilterSelective ARGS_VALUES “\n[[:space:]]*(to|bcc|cc)[[:space:]]*:.*@”
    The ModSecurity site also conveniently includes a package of rules, including PHP-related rules, grouped by function. Note that there are “SQL Injection Attack” rules in the “general” conf file. You can include the rule groups you want by using an “Include” directive in the ModSecurity section of your httpd.conf file; i.e. “Include conf/modsecurity-php.conf”.
    These rules are a good place to start, as are the rules from gotroot.com. You may need to tweak these a little bit, and be selective in which rulesets you apply. For example, often aggregating IP addresses such as AOL proxies are blocked due to the blacklist rules, which may not be what you want.
    This is only a brief introduction, but I hope you will try ModSecurity for yourself, and discover how powerful it can be.
  • Enable caching in MySQL
    By sps on February 2nd, 2009 | No Comments Comments

    Log into your mysql

    $ mysql -u root –p

    Output:

    Enter password:

    Welcome to the MySQL monitor. Commands end with ; or \g.

    Your MySQL connection id is 16 to server version: 4.1.15-Debian_1-log
    Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

    mysql>

    Now setup cache size 32Mb:
    mysql> SET GLOBAL query_cache_size = 33554432;    
    
    Query OK, 0 rows affected (0.00 sec)
    mysql> SHOW VARIABLES LIKE 'query_cache_size';

    Output:

    +——————+———-+

    | Variable_name | Value |

    +——————+———-+

    | query_cache_size | 16777216 |

    +——————+———-+

    You can setup them in /etc/my.cnf (Red Hat) or /etc/mysql/my.cnf (Debian) file:
    # vi /etc/my.cnf
    Append config directives as follows:

    query_cache_size = 33554432
    query_cache_type=1
    query_cache_limit=2096576