我想在我網站的截止日期后進行重定向。
如果我寫這個,目前一切正常:
RewriteEngine On
SetEnv DEADLINE 16/06/2022_19h30
RewriteCond %{TIME_DAY}/%{TIME_MON}/%{TIME_YEAR}_%{TIME_HOUR}h%{TIME_MIN} >=16/06/2022_19h30
RewriteRule ^index.php$ read_only/index.html [L]
使用環境變數的好處是我可以在 PHP 檔案的其他地方使用它
那么有沒有辦法在當前時間和 DEADLINE 變數之間進行測驗?
uj5u.com熱心網友回復:
您可以這樣做,但您需要使用SetEnvIf指令設定變數,以便在 .htaccess 中進行評估RewriteCond:
首先定義這個變數:
SetEnvIf Host ^ DEADLINE=20220616193000
然后使用RewriteCond運算式在 .htaccess 中使用它:
RewriteEngine On
RewriteCond expr "%{TIME} -ge env('DEADLINE')"
RewriteRule ^index\.php$ read_only/index.html [L,NC]
由于使用exprin RewriteCond,需要 Apache 2.4
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/492657.html
