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 靜態化 功能 。