問題描述
我想在 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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。