Tag Archive: linux

对于Linux服务器管理员来说, .htaccess文件几乎没人不知道。现在大部分网站都用它还做URL rewrite。URL 路径改写几乎是流行的CMS的必备功能。
但是Htaccess还有其他很多强悍的功能:

1. 设置时区

这个设置会影响PHP中的date函数
SetEnv TZ [Time zone]

2. 301网址重定向

现在主要的搜索引擎都已支持301重定向,这个功能对于网站改域名非常重要
Redirect 301 http://eood.cn http://blog.eood.cn

3.跳过下载确认对话框

现在很多网址下载文件都会弹出打开或者保存文件的对话框,如何跳过这个对话框直接打开文件?
AddType application/octet-stream .pdf
AddType application/octet-stream .zip
AddType application/octet-stream .mov

4.省略域名中的www

SEO中很重要的一条就是每个网页只有一个链接指向,否则会被判定为重复文章,如何让www的URL全部指向省略www的URL?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.eood.cn [NC]
RewriteRule ^(.*)$ http://eood.cn/$1 [L,R=301]

5.自定义错误页面

ErrorDocument 401 /error/401.php
ErrorDocument 403 /error/403.php
ErrorDocument 404 /error/404.php
ErrorDocument 500 /error/500.php

6.压缩文件

在客户端请求过程中对文件压缩,可以提高下载速度

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

7.缓存大文件

WEB游戏如今非常盛行,Flash客户端动辄几M,每次都让玩家加载肯定是不行的,如何让不常更新的大文件缓存在客户端?

Header set Cache-Control “max-age=2592000″

8.禁止在此目录执行脚本

AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI

Sell your blog links

Activate Linode VPS
Best VPS Service

Install rar in linux:
$ cd /tmp
$ wget http://www.rarlab.com/rar/rarlinux-3.6.0.tar.gz
$ tar -zxvf rarlinux-3.6.0.tar.gz
$ cd rar
$ ./unrar
# cp rar unrar /bin

Determing filetype:
file xxxx

How to count the top items in txt files?
awk ‘{ print $1}’ /path/to/input.txt sort| uniq -c | sort -nr > /path/to/top-get-ips.txt

Detect the checkbox value and onchange action in Jquery:
$(“#chkBox”).click(function(){
if ($(“#chkBox”).is(“:checked”)) {
alert(“Stopping…”);
} else {
alert(“Starting…”);
}
});

Install VMware under windows as the development environment.
IP settings:

VMware provides:bridge,Host Only and NAT 3 ways. I think NAT is the best way to go:

1. VMware network adapter chosing NAT.
2. Edit=>virtual network editing=>NAT,NAT gateway ip address is 192.168.X.2
3. Under windows ipconfig to see the ip address of VMnet8, is 192.168.X.1
4. Set the ip address to be 192.168.X.55/255.255.255.0
/etc/network/interfaces
5. vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDRESS=192.168.X.55
NETMASK=255.255.255.0
GATEWAY=192.168.X.2

6. /etc/init.d/network restart

Domain setting:
Edit C:\WINDOWS\system32\drivers\etc\hosts Map the domain and the VM ip address.

Share folder setting:
Insert the linux.iso to the CDROM of VM. Install the tools.
./install.pl
Choose VM > Settings > Options and click Shared folders.
And your folder of windows will local in /mnt/hgfs/share