Posts tagged amp

Mod Rewrite 推薦資源

正則表達式工具firefox擴展:Regular Expressions Tester
正則表Introduction to the Tutorial:

http://gnosis.cx/publish/programming/regular_expressions.html

Apache文檔之mod_rewrite介紹:

http://www.uplinux.com/download/doc/apache/ApacheManual/mod/mod_rewrite.html

More >

URL重寫舉例

1. 給子域名加www標記

RewriteCond %{HTTP_HOST} ^([a-z.]+)?example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .? http://www.%1example.com%{REQUEST_URI} [R=301,L]

這個規則抓取二級域名的%1變量,如果不是以www開始,那么就加www,以前的域名以及{REQUEST_URI}會跟在其后。

2. 去掉域名中的www標記

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L]

More >

RewriteRule指令

RewriteRule Pattern Substitution [Flags]
在模式(Pattern)和替換(Substitution)中使用正則表達式來匹配相應的字符。
譬如有如下的URL:

http://www.example.com/display.php?country=USA&state=California&city=San_Diego

REQUEST_URI的值是“/country=USA &state=California&city=San_Diego”,要將國家州城市信息更友好的顯示給用,要顯示成這樣:

http://www.example.com/USA/California/San_Diego

More >

我的host檔案

C:\WINDOWS\system32\drivers\etc\hosts

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a ‘#’ symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
##########################################################################
# Created by LinHongJun for personal purpose.
##########################################################################
# To map IP address to host name.
127.0.0.1 localhost
##########################################################################
# To block internet connection.
#
##########################################################################
# To block host names of ads and tracking fxxking cookies.
0.0.0.0 ads1.msn.com
0.0.0.0 rad.msn.com
0.0.0.0 rad.live.com
# To block host names of ads and tracking cookies.
# google
0.0.0.0 googlesyndication.com
0.0.0.0 pagead1.googlesyndication.com
0.0.0.0 pagead2.googlesyndication.com
0.0.0.0 pagead3.googlesyndication.com
0.0.0.0 pagead4.googlesyndication.com
0.0.0.0 pagead5.googlesyndication.com
0.0.0.0 www.google-analytics.com
# sina
0.0.0.0 ad1.sina.com.cn
0.0.0.0 ad2.sina.com.cn
0.0.0.0 ad3.sina.com.cn
0.0.0.0 ad4.sina.com.cn
0.0.0.0 ad5.sina.com.cn
# yahoo
0.0.0.0 cm.p4p.cn.yahoo.com
# allyes
0.0.0.0 allyes.com
0.0.0.0 adsina.allyes.com
0.0.0.0 stbanner.allyes.com
0.0.0.0 sina.allyes.com
# yieldmanager
0.0.0.0 ad.yieldmanager.com
0.0.0.0 content.yieldmanager.com
0.0.0.0 content.yieldmanager.edgesuite.net
# tribalfusion
0.0.0.0 tribalfusion.com
0.0.0.0 a.tribalfusion.com
# keyrun
0.0.0.0 keyrun.com
0.0.0.0 www1.keyrun.com
0.0.0.0 pic0.keyrun.com
0.0.0.0 pic1.keyrun.com
0.0.0.0 pic2.keyrun.com
# media-servers
0.0.0.0 media-servers.net
0.0.0.0 ad.media-servers.net
0.0.0.0 content.media-servers.net
# doubleclick
0.0.0.0 ad.doubleclick.net
0.0.0.0 ad.cn.doubleclick.net
# adbrite
0.0.0.0 click.adbrite.com
0.0.0.0 4.adbrite.com
0.0.0.0 www.adbrite.com
0.0.0.0 adbrite.com
0.0.0.0 ads.adbrite.com
# overtrue
0.0.0.0 overture.com
0.0.0.0 www50.overture.com
0.0.0.0 cmhtml.hk.overture.com
# mediaplex
0.0.0.0 altfarm.mediaplex.com
0.0.0.0 mediaplex.com
# caishow
0.0.0.0 caishow.com
0.0.0.0 c03.caishow.com
# adrevolver
0.0.0.0 adrevolver.com
# revsci
0.0.0.0 ads.revsci.net
# firstadsolution
0.0.0.0 ad.firstadsolution.com
# ad-flow
0.0.0.0 ad.ad-flow.com
# zanox
0.0.0.0 ad.zanox.com
# advertising
0.0.0.0 advertising.com
# casalemedia
0.0.0.0 casalemedia.com
# doubleclick
0.0.0.0 doubleclick.net
# fastclick
0.0.0.0 fastclick.net
# layer-ads
0.0.0.0 layer-ads.de
# onestat
0.0.0.0 stat.onestat.com
# statcounter
0.0.0.0 statcounter.com
# mop
0.0.0.0 union.mop.com
# tom
0.0.0.0 ulinkdir.tom.com
# targetpoint
0.0.0.0 srs.targetpoint.com
# yahoo
0.0.0.0 rd.aliunion.cn.yahoo.com
# bahamut
0.0.0.0 ad.gamer.com.tw
0.0.0.0 lkasoo.bahamut.com.tw
# baidu
0.0.0.0 eiv.baidu.com
0.0.0.0 ma.baidu.com
0.0.0.0 hc.baidu.com
# 163
0.0.0.0 popme.163.com
# sohu
0.0.0.0 images.sohu.com
# qq
0.0.0.0 adsfile.qq.com
0.0.0.0 adsclick.qq.com
# misc
0.0.0.0 ad1.adpolestar.net
0.0.0.0 ad.wretch.cc
0.0.0.0 popunder.paypopup.com
0.0.0.0 zt958.com
0.0.0.0 536.net
0.0.0.0 qyeee.com
0.0.0.0 jia789.com
0.0.0.0 ewowo.com
0.0.0.0 yinsou.com
0.0.0.0 mmonly.com
0.0.0.0 www.mmonly.com
0.0.0.0 bbsbang.com
0.0.0.0 18gou.com
0.0.0.0 adultfriendfinder.com
0.0.0.0 counter.ixlink.net
0.0.0.0 m1.cn.2mdn.net
0.0.0.0 adserving.cpxinteractive.com
0.0.0.0 ad.adition.net
0.0.0.0 textlink.ixlink.net
# 如果你在玩Maple Story,那麼訪問官方網站的時候務必去掉下面這行.
0.0.0.0 tw.maplestory.gamania.com
##########################################################################

URL Rewrite mod_rewrite Notes

Rewirte主要的功能就是實現URL的跳轉,它的正則表達式是基于Perl 語言。可基于服務器級的(httpd.conf)和目錄級的 (.htaccess)兩種方式。如果要想用到rewrite模塊,必須先安裝或加載rewrite模塊。方法有兩種一種是編譯apache的時候就直接安裝rewrite模塊,別一種是編譯apache時以DSO模式安裝apache,然后再利用源碼和apxs來安裝rewrite模塊。

基于服務器級的(httpd.conf)有兩種方法,一種是在httpd.conf的全局下直接利用RewriteEngine on來打開rewrite功能;另一種是在局部里利用RewriteEngine on來打開rewrite功能,下面將會舉例說明,需要注意的是,必須在每個virtualhost里用RewriteEngine on來打開rewrite功能。否則virtualhost里沒有RewriteEngine on它里面的規則也不會生效。

基于目錄級的(.htaccess),要注意一點那就是必須打開此目錄的FollowSymLinks屬性且在.htaccess里要聲明 RewriteEngine on。
More >

PHP ob_start() 介紹

用PHP的ob_start();控制您的瀏覽器cache!

Output Control 函數可以讓你自由控制腳本中數據的輸出。它非常地有用,特別是對于:當你想在數據已經輸出后,再輸出文件頭的情況。輸出控制函數不對使用 header() 或 setcookie(), 發送的文件頭信息產生影響,只對那些類似于 echo() 和 PHP 代碼的數據塊有作用。

我們先舉一個簡單的例子,讓大家對Output Control有一個大致的印象:
Example 1.

<?php
ob_start(); //打開緩沖區
echo \"Hellon\"; //輸出
header("location:index.php"); //把瀏覽器重定向到index.php
ob_end_flush();//輸出全部內容到瀏覽器
?>

所有對 header()函數有了解的人都知道,這個函數會發送一段文件頭給瀏覽器,但是如果在使用這個函數之前已經有了任何輸出(包括空輸出,比如空格,回車和換行)就會提示出錯。如果我們去掉第一行的ob_start(),再執行此程序,我們會發現得到了一條錯誤提示:"Header had all ready send by"!但是加上ob_start,就不會提示出錯,原因是當打開了緩沖區,echo后面的字符不會輸出到瀏覽器,而是保留在服務器,直到你使用 flush或者ob_end_flush才會輸出,所以并不會有任何文件頭輸出的錯誤!

More >