[CPG] 改為含使用者帳號的短網址

| 九月 10, 2005 | 沒有迴響| 沒有引用| 1698 reads | Size: L, M, S | Edit: P, C, R |
| Category: CMS. |

    將 CPG 使用者相簿的網址改為短網址。

    原本的使用者相簿的網址是 http://CPG-URL//index.php?cat=10001

    這種形式,很不好記憶。

     

    搜尋過後,在官方論壇發現了這篇討論:

    http://coppermine-gallery.net/forum/index.php?topic=1659.20

     

    裡面的修改方式節錄如下:

    搜尋

    /**
    * Main code
    */

    這個部分,在前面加上

    $qq=$HTTP_SERVER_VARS["QUERY_STRING"];
    if (!strstr($qq,'=') and !empty($qq)) {
    $sql = "SELECT user_id " . "FROM {$CONFIG['TABLE_USERS']} " . "WHERE user_name = '". mysql_escape_string($qq) . "'";
    $result1 = db_query($sql);
    if (mysql_num_rows($result1)>0) {
    $u = mysql_fetch_array($result1);
    $HTTP_GET_VARS['cat'] = sprintf("1%04d",$u[0]);
    }
    mysql_free_result($result1);
    }

    這段原始碼。

    此時網址就可以使用 http://CPG-URL/?USERNAME 來連結。

     

    多打個問號總是麻煩,這時候可以利用 Apache Rewrite Mod 來轉換:

    假若安裝在子目錄 /gallery/ 下,在 CPG 的資料夾下新增一個 .htaccess,內容是:

    <Files .htaccess>
    deny from all
    </Files>

    RewriteEngine On
    RewriteBase /gallery/
    RewriteRule ^([A-Za-z_0-9-]+)/*$ /?$1 [R]

    如果你的資料夾直接在根目錄下,請使用這個 .htaccess

    <Files .htaccess>
    deny from all
    </Files>

    RewriteEngine On
    RewriteBase /
    RewriteRule ^([A-Za-z_0-9-]+)/*$ /?$1 [R]

     

    如此即可使用 http://CPG-URL/USERNAME 來連結。

     



Leave A Comment: