Use .htaccess to rewrite/redirect requests

How to redirect or rewrite URLs using .htaccess? File, called as .htaccess, can be used to rewrite URLs apart from doing other stuffs like application handlers etc. We can do some potent manipulations with our links, like, Transforming long URL’s into short, easy to remember URLs Transforming URLs having in-comprehensive query strings like “filename?id=carnivores&cat=animals” into […]

Block robots from accessing webpages using .htaccess

How to block Use htaccess file. this is run by server and ensured by the server that the rules written in it are enforced. On the other hand, robots.txt file is just a guideline file. Robots are not bound to follow it. To ensure denial of all requests for the restricted directory, put the following […]

Stop indexing files in a directory using .htaccess

How to stop indexing of files in a directory using .htaccess? Sometimes we do not want to show all the files in a directory (which by default is a behavior of web servers). That can be done using htaccess file. Though there’s a simple solution to this, put an index.html file showing a decent message […]

HTTP Authentication in URL not working in IE

IE (Internet Explorer) doesn’t work with user names and passwords in Web site addresses URLs (HTTP/S). Though, IE versions 3.0 to 6.0 support this. The following URL syntax may not work in Internet Explorer or in Windows Explorer, http(s)://username:password@mydomain.com Reason: Such URL syntax is used to automatically send username/password to a Web site which requires […]

How to increase file upload limit using .htaccess

Sometimes sever settings do not allow you to upload files more than a fixed limit (usually 2 MB). But, some websites might require allowing files more than this limit. In such cases we need to set some options in httpd.conf configuaretion file. This sometimes is not allowed on shared servers. “.htaccess” file comes to the […]

How To Send Mail Using Mail Command in UNIX

Sometimes we need to send e-mails from UNIX command-line itself. Sometimes we need to write a small script to do so. Here’s what we need to do for such tasks. We can send mail in UNIX using “mail” command. Syntax is as follows, mail -s “Subject” -c “any_cc_email_id” -b “any_bc_email_id” “comma_separated_To_email_id” But the above syntax […]

How to know if a file exists on the web or not, in PHP?

I have listed a few methods in PHP to check the existence of a file on the web. <?php $fileURL = “http://www.some-domain.com/image.jpg”; echo “Checking the existence of $fileURL<br>”; ?> Method 1: <?php $a = microtime(true); //start time in microseconds of 1st method echo date(“d/m/y : H:i:s”, time()), ” “,$a, “<br>”; get_http_response_code($fileURL); //fast but not fool […]

How to remove last comma from a string in PHP?

To remove/trim the last/trailing or first/heading comma from a string, one should first confirm that the last character of the string is comma itself and nothing else. This would make the code foolproof and prevent accidental removal of characters other than comma. A few methods are described here and listed in the order of increasing […]