ShopNC 商城系統偽靜態配置分服務器層重寫規則與程式碼層開關兩步。本文針對 B2B2C 多商戶版與 C2C 單商戶版,分 Windows (IIS) 與 Apache 兩種環境詳細說明,含常見坑點避雷。
htaccess.txt 重命名為 .htaccessdata/config/config.ini.php(勿用記事本,用 Notepad++/VS Code):
$config['url_model'] = false; // 改為 $config['url_model'] = true;
a2enmod rewrite → 重啟 Apachehtaccess.txt → .htaccessdata/config/config.ini.php:$config['url_model'] = true;/shopnc/),需修改 .htaccess 中 RewriteBase /shopnc → RewriteBase /mod_rewritehtaccess.txt → .htaccessRewriteBase| 現象 | 原因 | 解決 |
|---|---|---|
| 開啟後幫助中心鏈接 404 | 規則缺失或 RewriteBase 錯誤 | 檢查 .htaccess 完整性、修正 RewriteBase |
| config.ini.php 修改不生效 | 用記事本編輯導致 BOM/編碼錯誤 | 用專業編輯器(UTF-8 無 BOM) |
| 後台開啟按鈕灰色/無反應 | Apache 未啟用 rewrite 或 .htaccess 缺失 | 先完成服務器層配置再操作後台 |
| 靜態文件(css/js/圖片)404 | 重寫規則攔截靜態資源 | .htaccess 加入 RewriteCond %{REQUEST_FILENAME} !-f 排除實體文件 |
RewriteEngine On
RewriteBase /shopnc/ # 根目錄改為 /
# 排除實體存在的文件/目錄
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# 核心路由轉發
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
域名/index.html 或 域名/goods-123.html 類偽靜態 URLaccess.log 確認請求轉發至 index.php