Saturday, May 22, 2010
Use of .htaccess file
How to deny IP specific addresses?
# vi /home/user/public_html/.htaccess
Order allow, deny
Deny from 192.168.0.10
Deny from 212.155.
Deny from 1.2.3.4 5.6.7.8 127.0.0.1
Allow from all
How to prevent or allow directory listing?
The following line enables Directory listing.
Options +Indexes
The following disables directory listing for your web site.
Options –Indexes
With .htaccess file you can control which files to be ignored when creating a directory list.
For example:
IndexIgnore *.gif *.zip *.txt
Will make the apache server to skip all gif, zip and txt files from the directory list.
IndexIngnore *
Will just create an empty directory list.
You can use custom error pages for any error as long as you know its number (like 404 for page not found) by adding the following to your .htaccess file:
ErrorDocument errornumber /file.html
For example if I had the file notfound.html in the root direct
ory of my site and I wanted to use it for a 404 error I would use:
ErrorDocument 404 /notfound.html
Protecting a folder:
cd /home/user/public_html/
htpasswd -c .htpasswd username
the above command will create .htpasswdfile
To password protect a folder on your site, you need to put the following code in your .htaccess file:
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName "My Secret Folder"
Require valid-user
Hotlink Protectection:
You can prevent the hot-linking of your images by creating a .htaccess file with the following content:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?your-domain.com/.*$ [NC]
RewriteRule \.(gif|jpe?g|png)$ - [F]
To block other type of files, just add their extension to the list above. For example to block movie files:
RewriteRule \.(mov|avi|wmv|mpe?g)$ - [F]
The Hot-Linking prevention is based on an Apache module called ModRewrite.
Redirection:
The Apache web server provides several way for setting up redirects.
The most simple one is using the “Redirect” directive:
Redirect /folder
http://www.example.com/newfolder
With such a line in your .htaccess if a visitor tries to load
http://www.example.com/folder
he will be redirected to
http://www.example.com/newfolder
You can add a status code to the Redirect directive. For example for Permanent 301 redirect you can use:
Redirect permanent /folder
http://www.example.com/newfolder
Another useful directive is the RedirectMatch. With it you can use regular expressions in the redirect condition. For example
RedirectMatch "\.html$"
http://www.example.com/index.php
This will redirect all requests to files that end with .html to the index.php file.
Introduction to mod_rewrite and some basic examples:
Create easy to remember URLs or also known as COOL URIs, other call them Search Engine Friendly URLs. For example you have some complicated site driven by some server-side scripting language: PHP, Perl, etc. In general its URLs will look like
http://www.example.com/view.php?cat=art ... 20&lang=en
It is not easy to remember such URL.
Using ModRewrite you can make the URL look like:
http://www.example.com/en/articles/10-2
Here is the code:
RewriteEngine On
RewriteRule ^([a-z]*)/([a-z]*)/([1-9]+)(-[1-9]+)? $
Issue: Unable to view the images from php based website
Error:
PHP Fatal error: Call to undefined function imagecreatefromstring()
Fix:
Install the following packages OR recompile your PHP with gd libraries.
gd-2.0.33-9.4.el5_4.2 (Example version only)
gd-devel-2.0.33-9.4.el5_4.2
php-gd-5.2.12-3.el5
Then Restart the httpd,
/etc/init.d/httpd restart
Thursday, May 20, 2010
My SQL Privilege setting for table
This can be done from control panel itself.
Insertion Denied Error
Please follow below guide for this:
http://www.psoft.net/HSdocumentation/user/mysql_support.html#userprivileges
Thanks,
Wednesday, May 19, 2010
Ip Block and Unblock
Through IP tables
iptables -nL |grep 96.252.13.66
The above command used to grep the particular ip from the iptables.
iptables -A INPUT -s 96.252.13.66 -j ACCEPT
The above command used to ALLOW the IP for our server
iptables -D INPUT -s 96.252.13.66 -j DROP
The above command used to DROP the IP for our server
Through CSF firewall
You can do the same operation through CSF firewall also
csf -r --> Used to Restart the CSF firewall>
csf -d ip -->Used to Deny the IP for our server
csf -a ip -->Used to Allow the IP for our Server
Invalid maildirsize file Error in cpanel
If you see the error "Invalid maildirsize file" when trying to update your email account password, or change the quota, or if you are just having issues with logging in you should try this:
Log into cPanel, click on File Manager, click on the folder icon next to the mail folder, click on the folder icon next to the domain name, click on the folder icon next to the email user name, then click on the file called maildirsize in that folder (don't click on the icon but the file's name itself). In the upper right hand list of links, click to delete the file. Once you delete it, it will reform for the account automatically and it should then have the correct quota size.
Sample Server php mail script
$to = "testsimp@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("
Message successfully sent!
");} else {
echo("
Message delivery failed...
");}
?>
Monday, May 17, 2010
Online Tools
Find your public IP:
http://whatismyip.com
http://myipaddress.com
performance check of Websites:
http://www.websiteoptimization.com/services/analyze/
http://alertra.com/spotcheck.php
http://www.siteuptime.com/users/quickcheck.php
http://host-tracker.com/
Black Listing Check for IP:
http://www.mxtoolbox.com/blacklists.aspx
http://www.au.sorbs.net/
http://dsbl.org/main
http://spamblock.outblaze.com/
http://www.spamcop.net/
http://www.spamhaus.org/index.lasso
http://njabl.org/lookup.html
PING test
http://network-tools.com/
http://www.websitepulse.com/help/testtools.ping-test.html
http://www.selfseo.com/ping_test.php
http://www.buildtelligence.com/online-ping-test.htm
Network Information of Website:
http://who.is/
http://checkdns.net/
http://intodns.com/
Zone NS Lookups
http://www.zoneedit.com/lookup.html
To visually Trace Route your IP
http://www.yougetsignal.com/tools/visual-tracert/
IP Location Tool
http://www.yougetsignal.com/tools/network-location/
To check Open port Of a connection
http://www.yougetsignal.com/tools/open-ports/
To check the websites residing in a Web server
http://www.yougetsignal.com/tools/web-sites-on-web-server/
Proxy-Links
http://anonymouse.org/anonwww.html
http://cowspy.com/
http://www.megaproxy.com/