Posts

Showing posts from March, 2012

Command to delete file older than n number of days

Following command can be used to delete files older than n number of days:

find /usr/local/apache/logs -type f -mtime +15 -exec rm -f {} \;

find - It will search the files in the directory.
/usr/local/apache/logs - destination of the directory.
type f - type is used to search by type of file syatem & f is to find the files only in directory.
-mtime +15 - mtime used to search files according to time & +15  to search files older than 15 days.
-exec rm -f - exec is used to run any command & rm -f to forcefully delete the files.
{} - it will hold the result from the find command and will pass it to exec as input. General syntax -exec <command> {}
\; - '\' will tell the find command to take ; as the end of command else it will also include the ; in find command. '\' is works as "escapes" and tell bash to take ; as new argument.

How to redirect a URL which consists of any specific word.

To redirect  URL which has any specific word in it to any other URL the following redirect rule can be used:

RedirectMatch "ravi$" http://ravigadgil.com/hello.html [R=301,NC]

ravi- Is the word which we are finding in the URL and if it appears than it will redirect to the desired URL.

http://ravigadgil.com/hello.html- Is the site to which we are redirecting in given example.

How to check Apache redirect using CURL command.

To check the Apache redirect we can use the CURL command which can tell us whether our reidrect is working correct or not in terminal it self.

curl -H "Host:ravigadgil.com" http://localhost/                       //it will tell us where our site is redirecting

curl -H "Host:ravigadgil.com" http://1.2.3.4/                         //it can be used if you know the IP of vhost

curl -H "Host:ravigadgil.com" http://localhost/abc.html          // it will tell where ravigadgil.com/abc.html is redirecting.

How to put permanent redirect in vhost

Following is the example of permanent redirect in which we are directing our site to another location.

<VirtualHost *>

        ServerName ravigadgil.com
        ServerAlias www.ravigadgil.com
        Redirect permanent / http://www.sitewheretoredirect.com       //destination address

</VirtualHost>

Simple vhost to redirect one site to another.

To create a vhost which does not have any doc root and is redirecting to any other site.

Following vhost will just redirect your site to any other site.


<VirtualHost *>
    ServerAdmin webmaster@ravigadgil.com                   //server admin email ID
    ServerName ravigadgil.com                                        //server name
    ServerAlias www.ravigadgil.com
    RewriteEngine On
    RewriteRule ^/(.*) http://www.yourdesiredsiteaddress.com [R=301,L]        //destination address
    RewriteCond %{REQUEST_METHOD} ^TRACE
    RewriteRule .* - [F]
</VirtualHost>