贏在執行

          這個世界上只有兩樣東西愈分享愈多,那就是智慧與愛。

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            17 Posts :: 11 Stories :: 13 Comments :: 0 Trackbacks
          Apache中URL Rewrite技術的實現     CSDN Blog推出文章指數概念,文章指數是對Blog文章綜合評分后推算出的,綜合評分項分別是該文章的點擊量,回復次數,被網摘收錄數量,文章長度和文章類型;滿分100,每月更新一次。

          最近我們公司的網站在進行優化動作,要想采用一種好點的技術,使得原來的PHP動態形式的網頁文件能夠被GOOGLE等搜索引擎更加容易地收入其中,目前我們已經采用了一些改進辦法:比如在后臺用PHP程序將原來的文件改成HTM內容;采用Apache的Path_Info技術,但覺得還是不夠強大,因此決定采用Apache中的URL Rewrite技術來試用一下。

          很早就注意到它了,但一直不知道怎么實現,今天咬咬牙,翻了N篇有關的文章,終于實現了一些基本的功能:

          1、修改http.conf

          在你要修改網站的根目錄下:


          DefaultType application/x-httpd-php
          rewriteengine on #必須
          options followsymlinks #必須
          RewriteRule /news/(\d+)\.html /news\.php\?id=$1 [N,L] #規則
          AllowOverride All

          2、先修改http.conf


          DefaultType application/x-httpd-php
          options followsymlinks
          AllowOverride All

          然后再在此目錄下建立一個.htacess文件,它的內容如下:
          rewriteengine on
          rewritebase /websamples/urlrewrite/
          RewriteRule news/(\d+)\.html news\.php\?id=$1 [N,L]

           

          這樣就實現了將http://localhost/news/1000.html 解析為 http://localhost/news.php?id=1000的功能

          附錄:(一個網站的.htacess文件)

          -------------------------------------------------------------------------------

          ErrorDocument 401 /error.php
          rewriteengine on
          rewritebase /websamples/urlrewrite/power-for-less.com/

          #show category
          #
          RewriteRule ^((laptop([^/]*))|(camcorder([^/]*))|(((digital)?).?camera([^/]*))|(power([^/]*))|(pda([^/]*))|(mobile([^/]*))|(two-way([^/]*))|(scanner([^/]*))|(mp3([^/]*)))\.htm(l?)$ babrand\.php\?fclassname=$1 [NC]

          #show brands
          #
          RewriteRule ^(laptop([^/]*))/([^/]+)\.htm(l?)$ series\.php\?fclassname=$1&fb_babrand=$3 [NC]
          RewriteRule ^(camcorder([^/]*))/([^/]+)\.htm(l?)$ series\.php\?fclassname=$1&fb_babrand=$3 [NC]
          RewriteRule ^(((digital)?).?camera([^/]*))/([^/]+)\.htm(l?)$ series\.php\?fclassname=$1&fb_babrand=$5 [NC]
          RewriteRule ^(power([^/]*))/([^/]+)\.htm(l?)$ series\.php\?fclassname=$1&fb_babrand=$3 [NC]
          RewriteRule ^(pda([^/]*))/([^/]+)\.htm(l?)$ series\.php\?fclassname=$1&fb_babrand=$3 [NC]
          RewriteRule ^(mobile([^/]*))/([^/]+)\.htm(l?)$ series\.php\?fclassname=$1&fb_babrand=$3 [NC]
          RewriteRule ^(two-way([^/]*))/([^/]+)\.htm(l?)$ series\.php\?fclassname=$1&fb_babrand=$3 [NC]
          RewriteRule ^(scanner([^/]*))/([^/]+)\.htm(l?)$ series\.php\?fclassname=$1&fb_babrand=$3 [NC]
          RewriteRule ^(mp3([^/]*))/([^/]+)\.htm(l?)$ series\.php\?fclassname=$1&fb_babrand=$3 [NC]

          #show products
          #
          RewriteRule ^(laptop([^/]*))/([^/]+)/(.+)\.htm(l?)$ product\.php\?fclassname=$1&fb_babrand=$3&code=$4 [NC]
          RewriteRule ^(camcorder([^/]*))/([^/]+)/(.+)\.htm(l?)$ product\.php\?fclassname=$1&fb_babrand=$3&code=$4 [NC]
          RewriteRule ^(((digital)?).?camera([^/]*))/([^/]+)/(.+)\.htm(l?)$ product\.php\?fclassname=$1&fb_babrand=$3&code=$6 [NC]
          RewriteRule ^(power([^/]*))/([^/]+)/(.+)\.htm(l?)$ product\.php\?fclassname=$1&fb_babrand=$3&code=$4 [NC]
          RewriteRule ^(pda([^/]*))/([^/]+)/(.+)\.htm(l?)$ product\.php\?fclassname=$1&fb_babrand=$3&code=$4 [NC]
          RewriteRule ^(mobile([^/]*))/([^/]+)/(.+)\.htm(l?)$ product\.php\?fclassname=$1&fb_babrand=$3&code=$4 [NC]
          RewriteRule ^(two-way([^/]*))/([^/]+)/(.+)\.htm(l?)$ product\.php\?fclassname=$1&fb_babrand=$3&code=$4 [NC]
          RewriteRule ^(scanner([^/]*))/([^/]+)/(.+)\.htm(l?)$ product\.php\?fclassname=$1&fb_babrand=$3&code=$4 [NC]
          RewriteRule ^(mp3([^/]*))/([^/]+)/(.+)\.htm(l?)$ product\.php\?fclassname=$1&fb_babrand=$3&code=$4 [NC]

          posted on 2008-02-01 00:41 飛雪(leo) 閱讀(260) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 嘉兴市| 北辰区| 阳谷县| 镇原县| 黄陵县| 冀州市| 阿合奇县| 巴东县| 台南市| 曲沃县| 巢湖市| 郴州市| 汝州市| 邓州市| 卢氏县| 肥东县| 涡阳县| 锦州市| 江阴市| 丹东市| 旬邑县| 湘潭市| 库伦旗| 高台县| 津市市| 陵川县| 九龙城区| 鄂州市| 长丰县| 洛扎县| 绥滨县| 康保县| 郸城县| 长寿区| 怀来县| 北宁市| 乌拉特前旗| 日喀则市| 汾阳市| 抚顺县| 收藏|