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]
相關文章
- 最佳實踐|Apache Pulsar 在拉卡拉的技術實踐Apache
- 在 Python 中實現 COMET 技術Python
- 博文|Apache Pulsar 在自研資料管道中的技術實踐Apache
- Apache Flink核心技術Apache
- VR虛擬現實技術在展廳中呈現的優勢VR
- 虛擬現實技術
- 大資料技術 - Apache Doris大資料Apache
- Cocos 技術派:實時競技小遊戲技術實現分享遊戲
- 實現VR直播的關鍵技術VR
- 快速理解容器技術的實現原理
- 數字展館中虛擬現實技術的使用優勢
- 技術基礎 | 在Apache Cassandra中改變VNodes數量的影響Apache
- Android技術棧(三)依賴注入技術的探討與實現Android依賴注入
- Oracle DUL的工作原理和技術實現Oracle
- 超實用:實現負載均衡技術的方式負載
- Apache Spark SQL的高階Join連線技術ApacheSparkSQL
- 技術探究:Apache Pulsar 的事務型事件流Apache事件
- 【轉載】SAP 系統中STO+VC 技術實現
- 一文讀懂Apache Flink技術Apache
- 六種實現負載均衡技術的方式負載
- 【Mysql核心技術】聊聊事務的實現原理MySql
- OLAP:實現高效BI分析的必備技術
- 平安人壽基於 Apache Doris 統一 OLAP 技術棧實踐Apache
- Redis | 第5章 Redis 中的持久化技術《Redis設計與實現》Redis持久化
- 京東技術中臺的Flutter實踐之路Flutter
- 【主流技術】Redis 在 Spring 框架中的實踐RedisSpring框架
- web技術分享| 虛擬列表實現Web
- 物件池技術和通用實現GenericObjectPool物件Object
- Apache Flink CDC 批流融合技術原理分析Apache
- Apache Kyuubi 高可用的雲原生實現Apache
- 技術卡片 - PHP 鏈式呼叫的簡單實現PHP
- 淘寶客?CPS技術是怎麼實現的?
- 前端技術探秘-Nodejs的CommonJS規範實現原理前端NodeJS
- 小程式直播連麥的技術實現與解析
- 微信掃碼登入的技術實現思考
- 現代通訊技術基礎中的基礎
- 中國工商銀行利用區塊鏈技術實現更快的資產交易區塊鏈
- 遊戲侵蝕現實:產業的成熟,讓遊戲技術跨入現實遊戲產業
- 如何用無伺服器技術實現最佳的DevOps實踐伺服器dev