讓Apache支持Rewrite靜態(tài)頁面重寫的方法
更新時間:2010年07月18日 17:51:01 作者:
Apache下Rewrite靜態(tài)頁面重寫的方法,需要的朋友可以參考下。
首先確定您使用的 Apache 版本,及是否加載了 mod_rewrite 模塊。
Apache 1.x 的用戶請檢查 conf/httpd.conf 中是否存在如下兩段代碼:
LoadModule rewrite_module libexec/mod_rewrite.so AddModule mod_rewrite.c
Apache 2.x 的用戶請檢查 conf/httpd.conf 中是否存在如下一段代碼: LoadModule rewrite_module modules/mod_rewrite.so
如果存在,那么在配置文件(httpd.conf)中加入如下代碼。此時請務(wù)必注意,如果網(wǎng)站使用通過虛擬主機來定義,請務(wù)必加到虛擬主機配置,即 中去,如果加在虛擬主機配置外部將可能無法使用。改好后然后將 Apache 重啟。
在確認開啟 mod_rewrite模塊之后,針對虛擬主機用戶,還可以通過創(chuàng)建.htaccess文件來達到url重寫的目的,首先要再設(shè)置的站點目錄中開啟 AllowOverride All(默認為 AllowOverride None);
.htaccess文件的內(nèi)容舉例如下 # 將 RewriteEngine 模式打開 RewriteEngine On # 修改以下語句中的 /dir 為你的站點目錄地址,如果程序放在根目錄中,請將 /dir 修改為 / RewriteBase /dir # Rewrite 修改相應(yīng)的系統(tǒng)規(guī)則
RewriteRule ^archiver/((fid|tid)-[\w\-]+\.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2 RewriteRule ^tag-(.+)\.html$ tag.php?name=$1 將創(chuàng)建好的.htaccess文件放在相應(yīng)的目錄下,此時便可以支持url靜態(tài)地址,方便搜索引擎的抓取
Apache 1.x 的用戶請檢查 conf/httpd.conf 中是否存在如下兩段代碼:
LoadModule rewrite_module libexec/mod_rewrite.so AddModule mod_rewrite.c
Apache 2.x 的用戶請檢查 conf/httpd.conf 中是否存在如下一段代碼: LoadModule rewrite_module modules/mod_rewrite.so
如果存在,那么在配置文件(httpd.conf)中加入如下代碼。此時請務(wù)必注意,如果網(wǎng)站使用通過虛擬主機來定義,請務(wù)必加到虛擬主機配置,即 中去,如果加在虛擬主機配置外部將可能無法使用。改好后然后將 Apache 重啟。
在確認開啟 mod_rewrite模塊之后,針對虛擬主機用戶,還可以通過創(chuàng)建.htaccess文件來達到url重寫的目的,首先要再設(shè)置的站點目錄中開啟 AllowOverride All(默認為 AllowOverride None);
.htaccess文件的內(nèi)容舉例如下 # 將 RewriteEngine 模式打開 RewriteEngine On # 修改以下語句中的 /dir 為你的站點目錄地址,如果程序放在根目錄中,請將 /dir 修改為 / RewriteBase /dir # Rewrite 修改相應(yīng)的系統(tǒng)規(guī)則
RewriteRule ^archiver/((fid|tid)-[\w\-]+\.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2 RewriteRule ^tag-(.+)\.html$ tag.php?name=$1 將創(chuàng)建好的.htaccess文件放在相應(yīng)的目錄下,此時便可以支持url靜態(tài)地址,方便搜索引擎的抓取
您可能感興趣的文章:
- apache的rewrite規(guī)則使用說明
- 開啟Apache mod_rewrite模塊示例代碼
- 13個實用的Apache Rewrite重寫規(guī)則
- 淺談apache和nginx的rewrite的區(qū)別
- Apache Rewrite實現(xiàn)URL的301跳轉(zhuǎn)和域名跳轉(zhuǎn)
- Apache Rewrite url重定向功能的簡單配置
- Linux下Apache安裝/增加mod_rewrite模塊的方法
- 學(xué)習(xí)Apache的mod rewrite、access寫法
- Apache rewrite的重寫相關(guān)的參數(shù)說明
- Apache rewrite重寫規(guī)則的常見應(yīng)用
- apache rewrite_module模塊使用教程
- 用ISAPI_Rewrite讓IIS也支持如Apache下.htaccess的URL重寫
- apache rewrite規(guī)則實現(xiàn)白名單
相關(guān)文章
在Linux分區(qū)或邏輯卷中創(chuàng)建文件系統(tǒng)的方法
這篇文章主要給大家介紹了關(guān)于如何在Linux分區(qū)或邏輯卷中創(chuàng)建文件系統(tǒng)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用Linux具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
windows apache環(huán)境下部署SSL證書讓網(wǎng)站支持https的配置方法
由于網(wǎng)站劫持與chrome瀏覽器默認不用https的提示網(wǎng)站不安全的原因,今天把SSL證書部署分享一下,希望能幫到大家2020-09-09

