3.實際操作:
例子:RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^MSIE [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^Opera [NC]
RewriteRule ^.* - [F,L] 這裡”-”表示沒有替換,瀏覽器為IE和Opera的訪客將被禁止訪問。
例子:
RewriteEngine On
RewriteBase /test
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ([^/]+)$ /test/$1.php
#for example: /test/admin => /test/admin.php
RewriteRule ([^/]+)\.html$ /test/$1.php [L]
#for example: /test/admin.html => /test/admin.php
限制目錄只能顯示圖片
< IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !^.*\.(gif|jpg|jpeg|png|swf)$
RewriteRule .*$ - [F,L]
< /IfModule>
在httpd-vhosts.conf中的寫法如下:
RewriteRule ^/world/([\d]+)_([A-Z]+).html$ /world/index.php?c=world&a=houseDetail&houseId={$1}&housetype={$2} [L]
RewriteRule ^/pinggu/([a-z]+)/([0-9]+).html /pinggu/index.php?c=pinggu&a=detail&city=$1&newcode=$2&rewrite=1 [NC,NE]
RewriteRule ^/jiaju/([a-z]+)/jc_c([\d]+).html /jiaju/index.php?c=jiaju&a=buildList&city=$1&cid=$2
RewriteRule ^/esf_bs/([a-z]*)_?(\d*)_?b?(\d*)/?m?([0-9,]*)x?(\d*)a?([0-9,]*)c?(\d*)p?([0-9,]*)d?(\d*)/$ /esf/index.php?purpose=%B1%F0%CAFB&city=$1&district=$2&comarea=$3&price=$4&orderby=$5&area=$6&tags=$7&buildclass=$8&equipment=$9&rewrite
RewriteRule ^/world/([\d]+)_([A-Z]+).html$ /world/index.php?c=world&a=houseDetail&houseId={$1}&housetype={$2} [L]
#住宅rewrite規則
RewriteRule^/zf/([a-z]*)_?(\d*)_?(\d*)/?p?(\d*)h?(\d*)m?(\d*)c?(\d*)([a-z0-9]*)/$ $8&&purpose=&city=$1&district=$2&comarea=$3&price=$4&room=$5&rtype=$6&tags=$7 [C,NC]
RewriteRule^s?(\d*)r?(\d*)o?(\d*)f?(\d*)d?(\d*)p?x?(\d*)&&(.*) /zf/index.php?$7&housetype=$1&railway=$2&towards=$3&floor=$4&equipment=$5&orderby=$6&rewrite [QSA,L,NC]
#別墅rewrite規則
RewriteRule ^/zf_bs/([a-z]*)_?(\d*)_?(\d*)/?p?(\d*)t?(\d*)m?(\d*)s?(\d*)([a-z0-9]*)/?$ $8&&purpose=%B1%F0%CA%FB&city=$1&district=$2&comarea=$3&price=$4&buildclass=$5&rtype=$6&housetype=$7 [C,NC]
RewriteRule ^h?(\d*)o?(\d*)f?(\d*)d?(\d*)p?x?(\d*)&&(.*) /zf/index.php?$6&room=$1&towards=$2&floor=$3&equipment=$4&orderby=$5&rewrite [QSA,L,NC]
#寫字樓rewrite規則
RewriteRule ^/zf_app_xzl/([a-z]*)_?(\d*)_?(\d*)/?p?(\d*)a?(\d*)t?(\d*)c?(\d*)r?(\d*)/? /zf/index.php?purpose=%D0%B4%D7%D6%C2%A5&app_type=app&city=$1&district=$2&comarea=$3&price=$4&area=$5&propertysubtype=$6&tags=$7&&railway=$8&rewrite [QSA,L]
#寫字樓rewrite規則
RewriteRule ^/zf_xzl/([a-z]*)_?(\d*)_?(\d*)/?p?(\d*)a?(\d*)t?(\d*)c?(\d*)r?(\d*)/? /zf/index.php?purpose=%D0%B4%D7%D6%C2%A5&city=$1&district=$2&comarea=$3&price=$4&area=$5&propertysubtype=$6&tags=$7&&railway=$8&rewrite [QSA,L]
#寫字樓rewrite規則
RewriteRule ^/zf_xzl/([a-z]*)_?(\d*)_?(\d*)/?p?(\d*)a?(\d*)t?(\d*)c?(\d*)r?(\d*)/? /zf/index.php?purpose=%D0%B4%D7%D6%C2%A5&city=$1&district=$2&comarea=$3&price=$4&area=$5&propertysubtype=$6&tags=$7&&railway=$8&rewrite [QSA,L]
RewriteRule ^/zf/([a-z]+)_xm([0-9]+)/$ /zf/index.php?c=zf&a=index&city=$1&projcodes=$2&src=xiaoqu&rewrite [L]