Apache中URLRewrite技術的實現
最近我們公司的網站在進行優化動作,要想採用一種好點的技術,使得原來的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]
相關文章
- javaweb中應用urlrewrite技術JavaWeb
- Apache偽靜態html(URLRewrite)設定法ApacheHTML
- Delphi中停靠技術的實現 (轉)
- apache中防止盜鏈技術(轉)Apache
- 最佳實踐|Apache Pulsar 在拉卡拉的技術實踐Apache
- 博文|Apache Pulsar 在自研資料管道中的技術實踐Apache
- 在 Python 中實現 COMET 技術Python
- Java UrlRewrite 實現網站URL重寫過程實錄Java網站
- UrlRewrite
- Apache Flink核心技術Apache
- Apache Spark技術實戰之7 -- CassandraRDD高併發資料讀取實現剖析ApacheSpark
- VR虛擬現實技術在展廳中呈現的優勢VR
- Apache Spark技術實戰之5 -- SparkR的安裝及使用ApacheSpark
- QA問答系統中的深度學習技術實現深度學習
- 虛擬現實技術
- Cocos 技術派:實時競技小遊戲技術實現分享遊戲
- 大資料技術 - Apache Doris大資料Apache
- 實現VR直播的關鍵技術VR
- 快速理解容器技術的實現原理
- 數字展館中虛擬現實技術的使用優勢
- 我對C++中THUNK一種實現技術的分析 (轉)C++
- 純技術貼:討論一個現實中的需求的架構架構
- 【區塊鏈技術實現】區塊鏈
- 【轉載】SAP 系統中STO+VC 技術實現
- 技術基礎 | 在Apache Cassandra中改變VNodes數量的影響Apache
- Oracle DUL的工作原理和技術實現Oracle
- 走在技術前沿的 iOS 架構實現 ?iOS架構
- 超實用:實現負載均衡技術的方式負載
- 京東技術中臺的Flutter實踐之路Flutter
- URLRewrite 講解
- 遊戲侵蝕現實:產業的成熟,讓遊戲技術跨入現實遊戲產業
- .net中ajax技術實現(自我總結,也許不對)
- Apache Spark SQL的高階Join連線技術ApacheSparkSQL
- 技術探究:Apache Pulsar 的事務型事件流Apache事件
- Android技術棧(三)依賴注入技術的探討與實現Android依賴注入
- Docker 核心技術與實現原理Docker
- 技術社群中的非技術話題
- Apache Spark技術實戰之3 -- Spark Cassandra Connector的安裝和使用ApacheSpark