【PHP程式設計+MySQL資料庫+PHPMaker整合教學+技術諮詢】 本月特價優惠中! 動態的架站程式時代,要自訂PHP程式頁面有那麼難嗎? MySQL『資料庫』與『資料表』,用PHP程式有那麼難控制嗎? 你不用死背『PHP程式』與『MySQL資料庫』語法也能獨自設計完成! 這是自動化軟體程式的年代 (用PHPMaker 設計在彈指之間就能自動生成整個 PHP 程式系統) 這不是:神話!程式軟體模組取代了這一切複雜的工程。 你可以自己建構自己專屬的: 訂購表單、會員名單、擴增購物車特殊頁面 →POS 系統、CRM 系統、ERP 系統、HRM 系統...等等 (更可以加入數據資源銷售賺錢!) 該是:【見證奇蹟】的時候了! 非親眼所見....真的無法相信此神兵利器!

使用 PHPMaker 2023(對於:URL Rewrite 網址重寫 )是怎麼一回事?

URL Rewrite (網址重寫)

生成的Web應用程式需要 URL重寫 ,您需要配置Web伺服器以將HTTP請求傳送到到PHP前端控制器檔案,即 index.php

預設情況下, .htaccess 檔案(對於 Apache)和 web.config 將為您的 Web 伺服器生成 檔案(對於 IIS)。

您可能不需要手動配置。 但是,如果生成的檔案不適用於您的 Web 伺服器,您應該檢查以下內容。

 

 Apache 阿帕奇

確保已安裝並啟用 Apache mod_rewrite 模組。 確保您的 .htaccess index.php 檔案位於同一目錄中。 .htaccess 檔案應包括以下重寫規則:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
 Apache 阿帕奇配置
注意 有兩組 .htaccess 檔案和 index.php,一組位於項目資料夾下,另一組位於“api”子資料夾下。

某些 Apache 伺服器需要 RewriteBase 指令,您可能需要加入:

A。 如果您生成到站台的 root 資料夾,

# For the .htaccess under the project folder
RewriteBase /
# For the .htaccess under the "api" folder
RewriteBase /api/
Apache 阿帕奇配置

b. 如果您生成到站台的子資料夾(例如“demo2023”),

# For the .htaccess under the project folder
RewriteBase /demo2023/
# For the .htaccess under the "api" folder
RewriteBase /demo2023/api/
Apache 阿帕奇配置

如果您的伺服器需要此設定,您可以點選 “工具”->“進階設定” 並設定 RewriteBase 指令 ,例如 / /demo2023/ ,然後重新生成 .htaccess 檔案。

確保您的虛擬主機配置了 AllowOverride 指令,以便 .htaccess 可以使用 重寫規則。 在文字編輯器中開啟 httpd.conf apache.conf ,找到 <Directory> 部分並將 AllowOverride 行變更為 ALL

如果啟用了 Apache 模組 mod_authz_core ,請確保正確配置 Require 指令,例如 Require all grants 授予對所有請求的訪問權限。

# DocumentRoot: The directory out of which you will serve your documents.
DocumentRoot "D:/my/path"
<Directory "D:/my/path">
    # ...
    # AllowOverride controls what directives may be placed in .htaccess files.
    AllowOverride All
    # Controls who can get stuff from this server.
    Require all granted
</Directory>
Apache 阿帕奇配置

 

nginx

的 Nginx 虛擬主機配置示例 這是域example.com 。 它偵聽連接埠 80 上的入站 HTTP 連線。

注意 以下假設 PHP-FPM 伺服器在連接埠 9123 上運行。 您必須更新 server_name error_log access_log 、 和 具有您自己的值的 指令。 root 指令 是應用程式公共文件根目錄的路徑, index.php 前端控制器檔案應位於此目錄中
server {
    listen 80;
    server_name example.com;
    index index.php;
    error_log /path/to/example.error.log;
    access_log /path/to/example.access.log;
    root /path/to/public;
    location / {
        try_files $uri /index.php$is_args$args;
    }
    location /api/ {
        try_files $uri /api/index.php$is_args$args;
    }
    location ~ \.php {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9123;
    }
}
nginx

 

網際網路訊息服務 (IIS)

不是 URL Rewrite模組 內建的,所以你需要下載並安裝 IIS URL 重寫模組 來自Microsoft 網站的 。 安裝後,您應該在 IIS 管理器中看到 URL 重寫模組: 您網站的

要執行映射,您可以使用 IIS 管理器,但直接使用 web.config 檔案更簡單。

確保 web.config index.php 檔案位於同一目錄(項目資料夾)中。 web.config 檔案應包括以下代碼:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="api" patternSyntax="Wildcard">
          <match url="api/*" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="api/index.php" />
        </rule>
        <rule name="slim" patternSyntax="Wildcard">
          <match url="*" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
XML

要了解有關 IIS URL 重寫的更多訊息,請參閱 使用 URL 重寫模組