問題描述
我想在 Windows 機器上使用子域建立一個本地網路。我不想為每個新的子域編輯 hosts 檔案。但是 Windows 不支援萬用字元子域,而 Codex 對此主題沒有任何用處。
我該怎麼辦?
最佳解決方案
有一個外掛:WP XAMPP Multisite Subdomains 。不幸的是,沒有英文描述。我會在這裡試試。以下指南將在具有子域的 mu.wp 下設定一個 multi-site 。
基本安裝
從 WordPress 和 XAMPP 的全新安裝開始。 Create a network 為子域。不要建立任何子站點。
我的 XAMPP 安裝在 E:xampp,E:wordpress.latest.final 中的 WordPress,以及 F:sites 中的我的站點特定目錄。目錄 F:sites_logs 用於日誌檔案。確保在以下示例中調整路徑到您的設定。
2. hosts 檔案
開啟 hosts 檔案。在 Win 7 上可能在 C:WindowsSystem32driversetchosts 上,您需要管理員許可權才能編輯它。
建立一個單獨的部分,如下所示:
# BEGIN XAMPP-127.0.0.2
127.0.0.2 mu.wp
# END XAMPP-127.0.0.2
注意我們使用 127.0.0.2,而不是 127.0.0.1 。這個很重要。
儲存檔案,關閉並忘記。
3. httpd-vhosts.conf
開啟/apache/conf/extra/httpd-vhosts.conf 中的 Apache vhosts 檔案。
建立一個新的虛擬主機。如果這是您的第一個虛擬主機,首先需要一個通用的 vhost 。
通用 vhost
應該是檔案中的第一個虛擬主機。
<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs"
ServerName localhost
<Directory "E:/xampp/htdocs">
Options Indexes FollowSymLinks
Options +Includes
AllowOverride FileInfo
AllowOverride All
Order allow,deny
Allow from all
DirectoryIndex index.php index.shtml index.html index.htm
</Directory>
ErrorLog "F:sites_logsdefault.error.log"
CustomLog "F:sites_logsdefault.access.log" combined
</VirtualHost>
我們的 multi-site vhost
<VirtualHost 127.0.0.2:80>
ServerName mu.wp
DocumentRoot "E:wordpress.latest.final"
<Directory "E:wordpress.latest.final">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "F:sites_logsmu.wp.error.log"
CustomLog "F:sites_logsmu.wp.access.log" combined
</VirtualHost>
確保所有的路徑是正確的!重新啟動 Apache 。
4. 安裝外掛
將外掛 WP XAMPP Multisite Subdomains 安裝為 MU-plugin 。通常在 wp-content/mu-plugins 。
完成。
您現在可以在 http://mu.wp/wp-admin/network/site-new.php 中建立新的子域,該外掛將自動更新 hosts 檔案,您的新站點立即可用。
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。