本地測試正常,部署至共享主機後出現問題:DedeCMS 主站正常,子目錄 WordPress 博客退出登入後訪問報 403。
index.php 可進入但無樣式、無法進後台。httpd.conf,發現根目錄配置:<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Satisfy all
</Directory>
將 Deny from all 改 Allow from all 雖解決 403 但引入安全隱患,復原。# Possible values for the Options directive are "None", "All" 附近配置,修改博客目錄對應區塊:/www/public/domain,博客在 /www/public/domain/blog(一級目錄非二級域名)。修改該目錄 Options 允許覆寫,重啟 Apache 後 403 解決,但出現目錄列表。博客根目錄缺少 .htaccess,Apache 預設開啟目錄瀏覽。
在博客根目錄建立 .htaccess 並寫入:
DirectoryIndex index.php index.html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
第一行設定預設首頁,後段啟用重寫規則。重新訪問即正常。
實踐出真知。共享主機環境下 CMS 與 WordPress 共存關鍵在於:
1. 正確配置虛擬主機/目錄的 AllowOverride 與 Options。
2. 確保 WordPress 目錄存在正確的 .htaccess 啟用重寫並設定預設文檔。
作者:夜星辰 @ 我要逆襲,轉載請保留原址。