我想知道如何使我的網站的 URL 與我的網站目錄中的檔案路徑不同。
例如,假設我希望我的網站語言位于 URL (mywebsite/en/index.php) 中,但我不想手動在我的網站目錄中創建每個 php 檔案,其中只包含我的主檔案中的一個包含,請問我該怎么做?如果需要,我正在使用 Nginx
uj5u.com熱心網友回復:
您可以使用 nginx 重寫正則運算式規則。 Nginx 重寫規則
假設您希望下面的 url 使用語言代碼訪問 index.php。
Url: https://yourwebsite.com/en/index.php
FilePath: /path/to/www/index.php
rewrite ^/(.*)/index.php$ /index.php?lang=$1 last;
# another example
# $1 is the matching characters in regex `(.*)`
rewrite ^/sales/(.*)/categories.php$ /some/path/cat.php?categories=$1 last;
不要忘記。所有 URL 都是虛構的,但所有檔案都是真實的。URL 不需要與真實檔案匹配。網址:https://yourwebsite.com/index.php可能會打/some.file.asp
查看官方 nginx 檔案了解更多詳細資訊。
希望能幫助到你。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/450984.html
