myAdBanner

2026年5月7日 星期四

xampp 設定 Apache VirtualHost(虛擬主機)

 

Apache VirtualHost(虛擬主機)

設定完之後,你會從:

http://localhost/project1

變成:

http://project1.local

這對 MVC 專案非常重要。

因為:

  • 路徑比較正常
  • Router 比較不會壞
  • AJAX 好處理
  • Cookie/session 好管理
  • 未來 API 比較穩

一、先確認你的環境

你目前大概是:

  • XAMPP
  • AppServ
  • WAMP
  • 自架 Apache

其中之一。


二、VirtualHost 的原理

Apache 會:

project1.local

對應到

D:\web\project1\

三、設定步驟(Windows)

我用最通用方式教你。


Step 1:建立專案目錄

例如:

D:\web\

裡面:

D:\web\project1
D:\web\opencart
D:\web\ci3

Step 2:修改 hosts 檔

Windows:

C:\Windows\System32\drivers\etc\hosts

用:

系統管理員身份

開啟記事本。


加入:

127.0.0.1 project1.local
127.0.0.1 opencart.local
127.0.0.1 ci3.local

Step 3:開 Apache VirtualHost

找到:

httpd-vhosts.conf

通常在:


XAMPP

C:\xampp\apache\conf\extra\httpd-vhosts.conf

AppServ

C:\AppServ\Apache24\conf\extra\httpd-vhosts.conf

Step 4:加入 VirtualHost

<VirtualHost *:80>
ServerName project1.local
DocumentRoot "D:/web/project1"

<Directory "D:/web/project1">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName opencart.local
DocumentRoot "D:/web/opencart"

<Directory "D:/web/opencart">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

<VirtualHost *:80>
ServerName ci3.local
DocumentRoot "D:/web/ci3"

<Directory "D:/web/ci3">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Step 5:確認 httpd.conf 有啟用 vhosts

找到:

#Include conf/extra/httpd-vhosts.conf

把:

#

拿掉:

Include conf/extra/httpd-vhosts.conf

Step 6:重啟 Apache

非常重要。


Step 7:測試

瀏覽器輸入:

http://project1.local

成功。


四、MVC 專案非常需要 .htaccess

尤其:

  • CodeIgniter
  • Laravel
  • OpenCart SEO URL

Apache 要啟用 rewrite_module

在:

httpd.conf

找到:

#LoadModule rewrite_module modules/mod_rewrite.so

拿掉:

#

變:

LoadModule rewrite_module modules/mod_rewrite.so

五、CodeIgniter 會用到 Rewrite

例如:

以前:

index.php/news/edit/3

之後:

/news/edit/3

六、VS Code 怎麼配合

之後:

File → Open Folder

開:

D:\web\project1

即可。



2024年10月22日 星期二

jquery 外掛 顯示隱藏的密碼欄位

 <script type="text/javascript" src="view/javascript/jquery/show-hide-password.min.js"></script>

 

2024年5月12日 星期日

刪除 Thumbs.db 方法

 @echo off
attrib -s -h -r Thumbs.db /s /d >nul
del Thumbs.db /s

2022年7月6日 星期三

php 轉換成 html

1. 先建立新的.htaccess檔案放在php檔案的目錄。

2. 建立一個Rewrite Engine (URL重寫工具)。

在檔案第一行寫上

RewriteEngine on 
 
3. 設定所在目錄 / 譬如 /test/
 
RewriteBase /test/
 
4. php 轉換成 html
 
RewriteCond %{THE_REQUEST} (.*)\.php  
RewriteRule ^(.*)\.php $1.html [R=301,L]  

RewriteCond %{THE_REQUEST} (.*)\.html  
RewriteRule ^(.*)\.html $1.php [L] 
 
------------------
完整檔案內容
------------------
RewriteEngine On
RewriteBase /test/

RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]

RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]  

2022年6月12日 星期日

windows 系統排程執行PHP程式

 步驟如下:

1. 下載 wget.exe 程式

https://eternallybored.org/misc/wget/

2. 將 wget.exe 複製到 C:\windows 資料夾內

3.  撰寫 bat 檔

autorun.bat 內容如下:

--------------------

C:\xampp\php>c:\windows\wget.exe -q http://localhost/autorunl.php

-------------------

參數說明:

-q 不會輸出執行結果

4.排程執行 autorun.bat


2022年5月31日 星期二

解決 html5 input type date 日期欄位 限制 年 只能輸入4碼

日期欄位用手打時,如沒限制 年 要輸入6碼才會跳 月 限制後就可以打4碼後自動跳月了

<input type="date" name="Birthday" value="" placeholder="生日" id="input-Birthday" class="form-control" min="1900-01-01" max="9999-12-31"/>

2022年5月30日 星期一