HTTPリクエストを捕捉してHTTPSにリダイレクトする方法
| 日付 | 2009/05/08 | 
|---|---|
| ID | 75313 (英語原文参照) | 
| バージョン | 11.4 | 
| プラットフォーム | Mac & Win | 
データベースに対するWebアクセスをセキュアなものに限定するメカニズムは4Dにありません。しかし、次のような方法を使えば、そのことを実現できます。
デコイのWebフォルダを使用すれば、すべてのリクエストはOn Web Connectionデータベースメソッドで処理することができます。具体的には、環境設定で選択したものとは別の場所にHTMLファイルをすべて置き、選択したフォルダは空にしておきます。このようにすれば、すべてのURLは無効なものになり、確実にOn Web Connectionデータベースメソッドが呼ばれるようになるからです。
次の図では、環境設定で選択されているWebFolderは空であり、デコイです。 Webフォルダにすべてのファイルが保存されています。
 
このようにセットアップしておき、On Web Connectionデータベースメソッドでは、リクエストがセキュアな接続かどうかを調べます。そうでなければ、リクエストをリダイレクトします。セキュアな接続であれば、リクエストを処理します。
`
` Database method: On Web Connection
`
C_TEXT($1;$2;$3;$4;$5;$6)
C_TEXT(WebFolder_t;requestedFile_t)
WebFolder_t:=Get 4D folder(Database Folder )+"web"
 ` This is the actual root folder for your html files
 ` I used a folder named "web" placed next to the structure
 ` NOTE: this folder must be different than what is selected
 ` as the HTML Root Folder in the Preferences, also the HTML 
 ` Root Folder (from preferences) should be empty
requestedFile_t:=WebFolder_t+(Replace string($1;"/";"\\"))
 ` This the path to the document being requested on the local file system
 ` NOTE: the "Replace string" command above is replacing
 ` the path delimiter for Windows, Macintosh should use : instead of \\
If (Secured Web connection)
 ` already secure connection
 If ((Test path name(requestedFile_t)=1))
  ` A file exists at the location requestedFile_t refers to
  `
  ` NOTE:
  ` if you wanted to, you can do additional checks on the file 
  ` or path to filter out unwanted strings/urls in this section of code.
  `
  ` For this example, i am just sending the file if it exists
  SEND HTML FILE(requestedFile_t)
  ` file exists so send it
 Else 
  ` file does not exist at the location (could be a folder)
  SEND HTML TEXT("404")
  ` Handle the 404 error
  ` NOTE: you can handle the 404 differently, this is just a quick example.
  End if 
Else 
 ` not a secure connection
 SEND HTTP REDIRECT("https://localhost"+$1)
  ` Redirect to the secure site
  ` NOTE: for this example i used localhost (don't forget to change this)
End if
