Wednesday, June 20, 2007
Here’s a quick and easy way to redirect a domain name to a specific page using mod_rewrite.
<Directory /path/to/document/root>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^.*$ http://domain.com/page.html [R=301,L]
</Directory>
This uses a 301 Permanent Redirect to the redirected page.
Done!!
Thursday, June 14, 2007
Do you need to download a text file instead of having your browser read the file?
All you need to do is use the code below, and name it download.php (or whatever you want).
<?
$file = 'filename.txt';
header('Content-type: text/plain');
header('Content-Length: '.filesize($file));
header('Content-Disposition: attachment; filename='.$file);
readfile($file);
?>
NOTE: Make sure you copy as is and do NOT leave any whitespace since you are sending headers.
All you need to do is replace filename.txt with the name of the filename you wish to have downloaded.
Now create another file, index.html perhaps, and just link to that php file, and you are all set. If you named the script download.php, you will just need:
<a xhref="download.php" mce_href="download.php" >Download Text File</a>
Done!!
Tuesday, June 12, 2007
Do you see ^M at the end of every line? Or ^M at random places where a new line should be?
This seems to happen when a DOS or Windows machine edits a text file. It is the Control Character for Carriage Return. To remove this, you will need to edit the file in Vi. Not sure how to do this in other text editors, but this will definitely work in Vi.
If you want to just remove the ^M characters, run this command in Vi:
s:%/^M//g
NOTE: Do not type Shift-6, Shift-m. That will not work. You will need to hold down ctrl while pressing V then M.If you want to replace each ^M character with a new line, run this command in Vi:
s:%/^M/^M/g
Again, hit ctrl-V-M to issue the second ^M in the replacement field.
Done!!