UCenter Home 啟用 URL Rewrite,需要對伺服器進行配置,增加相應的 Rewrite 規則,下面請看詳細說明:
一、 Apache Web Server+虛擬主機
1 、新增相應的 Rewrite 規則
在開始以下設定之前,請首先諮詢您的空間服務商,確認空間是否支援 Rewrite 以及是否支援對站點目錄中 .htaccess 的檔案解析 ,否則即便按照下面的方法設定好了,也無法使用。
注意:以下規則,僅適用於程式可以透過獨立域名或者二級域名直接訪問。 如果您的程式需要域名後面加目錄名 (比如:xxxxx) 的方式才可以訪問,那麼,您需要手工修改以下規則:
將 「RewriteBase /」 修改為 「RewriteBase /xxxxx」 ,其中,「xxxxx」 為您的程式目錄名。
RewriteEngine On RewriteBase / RewriteRule ^(space|network)-(.+).html$ $1.php?rewrite=$2 [L] RewriteRule ^(space|network).html$ $1.php [L] RewriteRule ^([0-9]+)$ space.php?uid=$1 [L]
然後儲存為檔案 .htaccess 。將 .htaccess 檔案上傳到程式所在的目錄中。
2 、進入 UCHome 後臺,常規設定,站點設定,根據需要開啟 URL Rewrite 功能 。
二、 Apache Web Server+獨立主機
1 、首先確定您使用的 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
如果沒有載入 mod_Rewrite 模組,您可以重新編譯 Apache ,並在原有 configure 的內容中加入 --enable-Rewrite=shared 。然後進行第二步操作。
如果載入了改模組,那麼請直接進行第二步操作。
2 、新增相應的 Rewrite 規則
在 Apache 配置檔案 (通常就是 conf/httpd.conf) 中加入如下程式碼:
注意:
1) 如果網站使用透過虛擬主機來定義,請務必加到虛擬主機配置中去,否則將可能無法使用。改好後重啟 Apache 。
2) 以下規則,僅適用於程式可以透過獨立域名或者二級域名直接訪問。如果您的程式需要域名後面加目錄名的方式才可以訪問,那麼,您需要手工修改以下規則:
將 「^/」 修改為 「^/xxxxx/」 ,其中,xxxxx 為您的程式目錄名 。
RewriteEngine On RewriteRule ^/(space|network)-(.+).html$ /$1.php?rewrite=$2 [L] RewriteRule ^/(space|network).html$ /$1.php [L] RewriteRule ^/([0-9]+)$ /space.php?uid=$1 [L]
3 、進入站點設定,根據需要開啟 URL 靜態化 功能 。