microsoft word - migrating php applications to iis …€¦ · web viewtitle microsoft word -...

20
Microsoft ® 虛虛虛虛虛 虛 PHP 虛虛虛虛虛虛虛 IIS 7.0

Upload: others

Post on 08-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

Microsoft® 虛擬實驗室將 PHP 應用程式移轉至 IIS 7.0

Page 2: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

Migrating PHP Applications to IIS 7.0目錄將 PHP 應用程式移轉至 IIS 7.0                    1練習 1 將 PHP 應用程式移轉至 IIS 7.0                   2

Page 3: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

Page 1 of 15

Migrating PHP Applications to IIS 7.0

將 PHP 應用程式移轉至 IIS 7.0

目標

案例

完成此實驗室練習之後,您將能: 在 IIS 7.0 上安裝 PHP 支援 下載並安裝 PHP 架構 啟用 IIS 以透過 FastCGI 為 PHP 應用程式提供服務 在現有的網站裝載 PHP 內容 建立獨立的虛擬目錄以存放 PHP 內容並設定權限 為 PHP 內容建立獨立的網站 設定額外的 PHP 設定 移轉 mod_rewrite URL 重寫規則此實驗室課程示範將 PHP 應用程式移轉至 IIS 7.0 的典型處理方式。它也提供數個將 PHP 應用程式移轉至 IIS 7.0 平台的典型案例,並提供其 IIS 7.0 組態。

完成此實驗室練習的預估時間 60 分鐘在此實驗室練習中使用的 電腦 Lab5_PHPWindows

此實驗室練習中所有電腦的 Administrator 帳戶密碼是:P @ ss w 0r d

Page 4: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

練習 1

將 PHP 應用程式移轉至 IIS 7.0

案例IIS 7.0 仍提供其他 PHP 裝載選項 (CGI 與 ISAPI),但 FastCGI 提供可用於裝載 PHP 應用程式的高可靠性基礎與效能。FastCGI 是 Windows Vista (SP1)、Windows Server 2008 與 Windows Server Core 2008 中模組化 IIS 功能集的一部分。工作 詳細步驟在下列電腦上完成下列工作:

MACHINENAME1. 在 IIS 7.0 上安裝 PH

P 支援

a. 按一下 [開始],然後選取 [伺服器管理員]。b. 展開 [角色]。c. 選取 [網頁伺服器 (IIS)] 角色。d. 按一下 [新增角色服務]。e. 選取 [應用程式開發] 下的 [CGI] 角色服務。f. 按一下 [下一步],然後按一下 [安裝]。g. 完成時請按一下 [關閉] 以關閉 [伺服器管理員]。

Page 5: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

2. 設定 PHP 架構 注意:PHP 架構從 PHP 5.2+ 就以已針對 Windows 最佳化,因此 PHP 在 Windows (特別是 IIS/FastCGI) 中能更可靠、更有效率地執行。從 PHP 5.2 開始,PHP 就特別針對 FastCGI 裝載模式提供非執行緒安全 (non-thread-safe) 版本,可提供超高的效能。a. 使用 Windows 檔案總管瀏覽至 C:\PHP。b. 將 php.ini-recommended 重新命名為 php.ini。c. 編輯 php.ini 檔案內容並取消註解一些行,以進行下列變更:

<<  cgi.fix_pathinfo = 1   cgi.force_redirect = 0   fastcgi.impersonate = 0;   error_reporting = E_ALL & ~E_NOTICE>>

注意:請務必變更 php.ini 檔案中現有設定的值,因為這些設定大部分都已存在。fastcgi.impersonate 設定控制當 PHP 存取並執行 PHP 指令碼時,是否會模擬 IIS 所提供的已驗證的使用者。可能有數個不同的權限模型牽涉到啟用或停用模擬。為了簡化設定程序,我們建議您停用模擬,並讓 PHP 以父應用程式集區的身分識別執行。d. 儲存並關閉檔案。e. 若要測試 PHP 是否安裝成功,請從命令提示字元執行下列命令:

C:\PHP>php –info

Page 6: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

3. 啟用 IIS 以透過 FastCGI 為 PHP 應用程式提供服務

注意:IIS 使用預設保全 (secure-by-default) 的原則:系統管理員必須啟用所要使用的功能。IIS 7.0 在其模組化項目中也遵循此原則,讓您可以完全移除任何不使用的伺服器功能。但是,既然我們已安裝 FastCGI,我們仍需要啟用它,讓它可以在伺服器上搭配 PHP 使用 (或用於特定應用程式)。在此工作中,我們將會讓整部伺服器可為 PHP 內容提供服務,方式是在伺服器層級建立 PHP 頁面的處理常式對應。

a. 按一下 [開始],輸入 inetmgr.exe,然後按下 ENTER。這樣會開啟 [Internet Information Services (IIS) 管理員]。

b. 在左邊樹狀檢視中選取本機伺服器。c. 按兩下 [IIS] 下的 [處理常式對應]。d. 按一下右邊 [動作] 窗格中的 [新增模組對應]。e. 輸入下列資訊,然後按一下 [確定]。

要求路徑:*.php

模組:FastCgiModule

可執行檔:C:\PHP\php-cgi.exe。 名稱:PHP via FastCGI (任意)

f. 按一下 [確定]。g. 收到 [是否要為此執行檔建立 FastCGI 應用程式?] 提示時,請按一下 [是]。h. 關閉 [IIS 管理員]。

Page 7: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

工作 詳細步驟4. 在現有的網站裝載

PHP 內容 注意:執行 PHP 內容最快的方式是將它新增至現有網站。這樣您就不需要設定任何額外的 IIS 組態或內容權限。在此工作中,我們會新增 PHP 頁面至「預設網站」(安裝 IIS 7.0 時會建立「預設網站」,您可以透過連接埠 80 存取此網站)。

a. 使用Windows 檔案總管瀏覽至 C:\inetpub\wwwroot。b. 建立info.php 檔案。c. 在該檔案中貼上下列內容:

<? php

  phpinfo();

?>d. 儲存並關閉檔案。e. 開啟 Internet Explorer 並要求 h tt p : //l oca lh o s t / i n fo. php 。f. 觀察 PHP 資訊頁面

5. 建立獨立的虛擬目錄以存放 PHP 內容並設定權限

注意:有時您會想要建立獨立的虛擬目錄來裝載 PHP 內容。這可能包括: 位於磁碟上獨立實體目錄的應用程式內容。 不想將其他應用程式內容與 PHP 應用程式混合時。 需要不同的權限設定時。

在此工作中,我們會新增獨立的虛擬目錄以裝載 PHP 內容,同時您仍能以預設網站 URL 階層的方式存取此虛擬目錄。我們也會設定為 PHP 內容提供服務所需的權限。a. 使用 Windows 檔案總管 瀏覽至 C:\inetpub。b. 建立 phpapp 目錄。c. 在 Windows 檔案總管中的 c:\inetpub\phpapp 目錄上按一下滑鼠右鍵。d. 按一下 [內容]。e. 按一下 [安全性] 索引標籤。f. 按一下 [編輯]。g. 按一下 [新增]。h. 在 [輸入物件名稱來選取] 中輸入 IIS_IUSRS。i. 按一下 [確定]。j. 按一下 [確定] 以接受預設權限 (讀取 + 執行)。k. 按一下 [確定] 以關閉 [phpapp 內容] 視窗。

Page 8: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

工作 詳細步驟注意:任何包含 PHP 內容的目錄必須至少授與下列權限: IIS_IUSRS:讀取。若 PHP 未設定為模擬已驗證的使用者 (fastcgi.impersonate

= 0,如此實驗室前面練習所示),這樣可讓 php-cgi.exe 處理程序存取 PHP 內容,同時任一 IIS 應用程式集區中的 PHP 也可存取該內容。 選擇性:若使用模擬,必須為使用應用程式的所有可能已驗證的使用者授與目錄的讀取權限,方式是將存取權授與個別使用者或所有此類使用者所屬的群組。 若使用匿名驗證,它必須將存取權授與在 IIS 中設定的匿名使用者 (預設是 II

S_IUSR)。 若使用 Windows 式驗證方法,必須將存取權授與所有可能的已驗證的使用者或那些使用者所屬的所有群組。 強烈建議您不要將「寫入」或「完整」存取權授與 IIS_IUSRS 或用以執行 PH

P 的帳戶。但是,若應用程式會寫入自己的檔案,有時「寫入」存取權是必要的。在此情況中,您只應該授與那些檔案或所需之子目錄的「寫入」存取權。但是,建議將所有寫入存取權設定至 Web 可存取的目錄結構之外。 若使用應用程式集區隔離來隔離應用程式,應該改為將目錄存取權授與指派至對應之應用程式集區的自訂帳戶。 或者,使用應用程式集區隔離時,可將存取權授與應用程式集區 SID。l. 開啟 [Internet Information Services (IIS) 管理員] (inetmgr.exe)。m. 展開伺服器節點,然後展開 [站台]。n. 在左邊樹狀檢視中的 [Default Web Site] 上按一下滑鼠右鍵。o. 按一下 [新增虛擬目錄]。p. 在 [別名] 中輸入 phpapp。q. 在 [實體路徑] 中輸入 C:\inetpub\phpapp。r. 按一下 [確定]。s. 使用 Windows 檔案總管瀏覽至 C:\inetpub\phpapp。t. 建立 hello.php 檔案。u. 在該檔案中貼上下列內容:

<?php echo("hello!"); ?>

v. 儲存並關閉檔案。w. 開啟 Internet Explorer 並要求 http://localhost/phpapp/hello.php。x. 觀察 hello 頁面。y. 關閉所有開啟的視窗。

Page 9: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

工作 詳細步驟 6. 為 PHP 內容建立獨立的 網站 注意:有時,可能需要以獨立的網站裝載 PHP 應用程式。例如下列情況:

您想要在不同的連接埠裝載 PHP 應用程式。 您想要在不同的網域裝載 PHP 應用程式。

在此工作中,我們會使用想要的連接埠與網域名稱來建立新的網站,以裝載 PHP 應用程式。

a. 開啟 [Internet Information Services (IIS) 管理員] (inetmgr.exe)。b. 展開伺服器節點。c. 在左邊樹狀檢視中的 [站台] 節點上按一下滑鼠右鍵。d. 按一下 [新增網站]。e. 在 [站台名稱] 中輸入 PHPSite。f. 在 [實體路徑] 中輸入 C:\inetpub\phpapp。g. 在 [連接埠] 中輸入 85。h. 按一下 [確定]。i. 開啟 Internet Explorer 並要求 h tt p : //l oca lh o s t:85 /h e l l o. php 。j. 觀察 hello 頁面。k. 開啟 [Internet Information Services (IIS) 管理員] (inetmgr.exe)。l. 在左邊樹狀檢視中的 [PHPSite] 上按一下滑鼠右鍵。m. 按一下 [編輯繫結]。n. 按一下 [新增]。o. 在 [主機名稱] 中輸入 phpsite。p. 按一下 [確定]。q. 按一下 [關閉]。r. 在 [記事本] 中編輯 C:\Windows\system32\drivers\etc\hosts 檔案。s. 新增下列 DNS 項目:

127.0.0.1 phpsite

t. 儲存並關閉 hosts 檔案。u. 開啟 Internet Explorer 並要求 h tt p : // p h p s i te /h e ll o. p h p

v. 觀察 hello 頁面。w. 關閉所有開啟的視窗。

Page 10: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

注意:在此工作中,我們建立一個站台以將我們的應用程式繫結到不同的連接埠與不同的網域名稱。您可以新增任意數量的繫結至站台,將 然後以任何可用的 IP 位址、連接埠與網域名稱的組合公開站台。您也可以使用此程序來建立 SSL 站台繫結 (雖然這也需要有效的伺服器憑證,而且可能牽涉到使用額外的 IIS 組態來適當地保護 SSL 站台的安全)。

7. 設定額外的 PHP 設定 注意:視應用程式使用的 PHP 功能而定,您可能需要設定額外的 PHP 設定。在此工作中,我們會設定 PHP以啟用數個其他常用的 PHP 功能。a. 使用 Windows 檔案總管瀏覽至 C:\PHP。b. 開啟 PHP 目錄中的 php.ini,並將 extension_dir 設定為 ext 子目錄:

<<

; Directory in which the loadable extensions (modules)reside.

extension_dir = "C:\PHP\ext?>>

c. 如果有需要,請開啟 PHP 安裝目錄中的 php.ini,然後新增/取消註解任何想要的延伸功能。以下範例示範如何啟用 mysql 延伸功能:

<<

; Windows Extensions

 ; Note that ODBC support is built in, so no dll is needed for it.

 ; Note that many DLL files are located in the extensions/ (PHP 4)

ext/ (PHP 5) ; extension folders as well as the separate PECL DLL   download (PHP 5). ; Be sure to appropriately set the extension_dir  directive.

 ;extension=php_bz2.dll ;extension=php_curl.dll ;extension=php_dba.dll ;extension=php_dbase.dll … extension=php_mysql.dll>>

d. 儲存並關閉檔案。e. 在 Windows 檔案總管中,在 [PHP] 目錄下建立 [session] 子目錄。f. 在 Windows 檔案總管中,在 [session] 目錄上按一下滑鼠右鍵。g. 按一下 [內容]。

Page 11: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

工作 詳細步驟h. 按一下 [安全性] 索引標籤。i. 按一下 [編輯]。j. 按一下 [新增]。k. 在 [輸入物件名稱來選取] 中輸入 IIS_IUSRS。l. 按一下 [確定]。m. 選取 [修改] 權限核取方塊中的 [允許]。n. 按一下 [確定]。o. 按一下 [session 內容] 視窗中的 [確定]。p. 開啟 PHP 目錄中的 php.ini,並將 session.save_path 設定為 session 子目錄:

<<

 session.save_path = ?C:\php\session?

>>

q. 儲存並關閉檔案。r. 按一下 [開始],然後選取 [命令提示字元]。s. 在命令提示字元中輸入 IISRESET,然後按下 ENTER 鍵。t. 使用 Windows 檔案總管瀏覽至 C:\inetpub\phpapp。u. 在 [phpapp] 目錄中建立 session.php。v. 在該檔案中貼上下列內容:

<?php

 if(!session_id())

 {  session_start();

 }

 if(isset($_SESSION[‘counter’]))

 {

  $_SESSION[‘counter’]++;

 }

 else

 {

  $_SESSION[‘counter’] = 1;

 }

 print ?You have visited this page ?.$_SESSION[‘counter’].? times during this session?;

?>

Page 12: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

w. 儲存並關閉檔案。x. 開啟 Internet Explorer 並要求 h tt p : // p h p s i te / s e s s i o n . p hp

y. 觀察計數器是否為 1。z. 再次要求 h tt p : //p h p s i te / s e s s i o n . php 。aa. 觀察計數器是否為 2。注意:PHP 預設使用檔案型工作階段狀態。您可以修改一些額外的工作階段設定,包括應使用 Cookie 或 URL 工作階段,以及要在第一個要求建立工作階段或需要明確地建立。bb. 使用 Windows 檔案總管瀏覽至 C:\PHP。cc. 在 PHP 安裝目錄中建立 [upload] 子目錄。dd. 在 Windows 檔案總管中的 [upload] 目錄上按一下滑鼠右鍵。ee. 按一下 [內容]。ff. 按一下 [安全性] 索引標籤。gg. 按一下 [編輯]。hh. 按一下 [新增]。ii. 在 [輸入物件名稱來選取] 中輸入 IIS_IUSRS。jj. 按一下 [確定]。kk. 選取 [修改] 權限核取方塊。ll. 按一下 [確定]。mm. 按一下 [確定] 以關閉 [upload 內容] 視窗。nn. 開啟 PHP 安裝目錄中的 php.ini,然後設定 file_uploads 與 upload_tmp_dir 設定:

<< ; Whether to allow HTTP file uploads.   File_uploads = On

 ; Temporary directory for HTTP uploaded files (will use system default if not  ; specified).Upload_tmp_dir = ?C:\php\upload?

>>

oo. 儲存並關閉 php.ini 檔案。注意:為求簡單,我們並沒有測試上傳指令碼。但是,如果要測試上傳指令碼,可以依照下列指示執行:

在磁碟上建立目錄,並設定權限以授與 IIS_IUSRS:修改存取權。 建立具有上傳表單的上傳頁面,此上傳頁面會將檔案儲存至在上一個工作中建立的目錄。

Page 13: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

工作 詳細步驟8. 設定預設文件 注意:IIS 7.0 提供預設文件功能,可讓系統將對於目錄的要求自動重新導向至預設文件 (如果有預設文件存在)。

在此工作中,我們將會設定預設文件以支援我們的主要 PHP 頁面。我們也會考慮使用替代方法,設定目錄來提供目錄清單而不重新導向到預設文件。

Page 14: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

a. 使用 Windows 檔案總管瀏覽至 C:\inetpub\phpapp。b. 在 [phpapp] 目錄中建立 index.php。c. 在該檔案中貼上下列內容:

<?php

echo("main page");

?>

d. 儲存並關閉 index.php 檔案。e. 按一下 [開始],然後按一下 [Internet Information Services (IIS) 管理員] 以開啟 [I

IS 管理員]。f. 展開伺服器節點,然後展開 [站台]。g. 按一下左邊樹狀檢視中的 [PHPsite] 站台。h. 按兩下預設文件。i. 按一下 [動作] 窗格中的 [新增],然後輸入 index.php。j. 按一下 [確定]。k. 開啟 Internet Explorer 並要求 h tt p : // p h p s i t e

l. 觀察 index 頁面回應。m. 切換至 [Internet Information Services 管理員]。n. 按一下左邊樹狀檢視中的 [PHPsite] 站台。o. 按兩下 [瀏覽目錄]。p. 按一下 [動作] 窗格中的 [啟用]。q. 在 Windows 檔案總管中,刪除 [C:\inetpub\phpapp] 目錄中的 index.php 檔

案。r. 開啟 Internet Explorer 並要求 h tt p : // p h p s i te 。s. 觀察顯示的目錄清單。t. 關閉所有開啟的視窗。

Page 15: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

工作 詳細步驟 9. 移轉 mod_rewrite URL

重寫規則 注意:許多 PHP 應用程式使用 Apache 的 mod_rewrite 模組來建立重新導向,或實作 Search Engine Friendly (SEO) 或自訂的 URL 配置。IIS 7.0 提供 URL Rewriter 模組,可用來實作 mod_rewrite URL 重寫規則 (當您在 IIS 7.0 中裝載 PHP 應用程式時)。

a. 開啟 [Internet Information Services (IIS) 管理員] (inetmgr.exe)。b. 展開伺服器節點,然後展開 [站台]。c. 按一下左邊樹狀檢視中的 [PHPSite]。d. 按兩下 [IIS] 下的 [URL Rewrite]。e. 按一下 [匯入規則]。f. 將下列 mod_rewrite 規則貼到 [重寫規則] 文字方塊:

RewriteCond %{REQUEST_URI} !^/(.*)\.\w+$

RewriteRule ^/?(.*)$ /$1.php [L,QSA]

g. [轉換的規則] 樹狀檢視將會自動顯示對應的 URL 重寫規則。h. 按一下 [套用] 以設定匯入的規則。i. 按一下 [返回規則] 以檢視目前作用中的規則。j. 開啟 Internet Explorer 並要求 h tt p : // p h p s i te / s e s s i o n

k. 觀察我們已經被重新導向到 session.php 頁面,但 PHP 延伸模組是隱藏的。l. 在 Internet Explorer 中要求 h tt p : //p h p s i te /h e ll o. php 。m. 觀察我們可以看到 hello.php 頁面。n. 使用 Windows 檔案總管瀏覽至 C:\inetpub\phpapp。o. 開啟 [phpapp] 中的 web.config 檔案。p. 此檔案將包含匯入的 URL 重寫規則。這些規則現在是應用程式的一部分,而

且可使用隨著應用程式內容部署的 Xcopy 複製到任一其他已安裝 URL Rewrite 模組的 IIS 7.0 伺服器。規則如下:

工作 詳細步驟

Page 16: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

<< <system.webServer>

 <rewrite>

   <rules>

   <rule name="Imported Rule 1" stopProcessing="true">

     <match url="^(.*)$" ignoreCase="false" />

           <conditions logicalGrouping="MatchAll">

           <add input="{SCRIPT_NAME}" negate="true"  pattern="^/(.*)\.\w+$" ignoreCase="false"/>           </conditions>           <action type="Rewrite" url="/{R:1}.php" appendQueryString="true" />         </rule>        </rules>       </rewrite>      </system.webServer>

>>

注意:在目前的 URL Rewriter 版本中,有一些問題可能會影響匯入規則的運作方式。您可能需要編輯產生的規則 (當匯入規則後),並進行下列變更: 設定 ignoreCase="true" 以確保規則不區分大小寫,因為大部分 IIS 7.0

URL 2都不區分大小寫。 使用 {URL} 取代規則中的 {REQUEST_URI} 或 {SCRIPT_NAME} 伺服器變數。因為第一個 URL Rewrite 版本中的已知問題,套用規則至靜態內容時此為必要動作。 例如,在進行變更之後,已修改的規則看起來應該像下面這樣:<<  <system.webServer>   <rewrite><rules>    <rule name="Imported Rule 1" stopProcessing="true">

    <match url="^(.*)$" ignoreCase="true" />    <conditions logicalGrouping="MatchAll">

    <add input="{URL}" negate="true" pattern="^/(.*)\.\w+$" ignoreCase="true"/>        </conditions>    <action type="Rewrite" url="/{R:1}.php" appendQueryString="true" />        </rule>      </rules>    </rewrite>  </system.webServer>>>

Page 17: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created
Page 18: Microsoft Word - Migrating PHP Applications to IIS …€¦ · Web viewTitle Microsoft Word - Migrating PHP Applications to IIS 7.0_Charles Author Mark Description Document was created

工作 詳細步驟q. 您也可以直接建立新的 URL 重寫規則,而不需要修改匯入的 mod_rewrite 規則。讓我們建立規則,以公開接受類別與子類別做為查詢字串參數 (topic.php?category=category&subcategory=subcategory) 的內部頁面 (使用 /category/subcategory 的 SEO URL)。

r. 使用 Windows 檔案總管瀏覽至 C:\inetpub\phpapp。s. 在 [phpapp] 目錄中建立 topic.php 頁面。t. 在該檔案中貼上下列內容:

<?php

echo("You requested the following:<br/>");echo($_GET['category']); echo("<br/>"); echo($_GET['subcategory']);

?>u. 儲存並關閉檔案。v. 切換到 [Internet Information Services (IIS) 管理員] (inetmgr.exe)。w. 按一下左邊樹狀檢視中的 [PHPSite]。x. 按兩下 [IIS] 下的 [URL Rewrite]。y. 按一下 [新增規則]。z. 選取 [User Friendly URL] 範本。aa. 按一下 [確定]。bb. 在 [輸入內部 URL 範例] 文字方塊中輸入 /topic.php?category=category&subc

ategory=subcategory。cc. 在 [選取對應的公用 URL 範例] 下拉式功能表中,將

/category/subcategory/ 表單維持為選取狀態。dd. 觀察系統是否自動建議規則的 regex 模式。ee. 選取 [建立對應的重新導向規則] 核取方塊。ff. 按一下 [確定]。gg. 選取新建立的規則,然後按一下 [上移] 將它們移動到先前匯入的自訂hh. 按一下繼承性對話方塊中的 [是]。ii. 切換到 Internet Explorer 並要求   h tt p : //ph p s i te / to pi c. p h p ?

category=iis7&subcategory=php

jj. 設定 category=iis7 與 subcategory=php 並觀察 topic.php 的回應。kk. 要求 h tt p : //p h p s i te /i i s 7 / p hp ll. 在類別仍是 iis7 且子類別是 php 的情況下,使用易記 URL 重寫規則,並觀察

topic.php 的回應。注意:[IIS 管理員] 中有一些其他範本可讓您快速建立重寫規則,而不需要開發複雜的規則運算式。您也可以匯入各種現有的 mod_rewrite 規則集。如果需要,您也可以使用 [IIS 管理員] 修改現有規則或從頭建立新規則,或直接使用組態語法來建立。