如何使用 mod_rewrite 確保網站一頁的安全

如何使用 mod_rewrite 確保網站一頁的安全

我想將我網站上幾個頁面的網址從 http 重定向到 https。

我知道如何使用 apache 虛擬主機中的重寫來對整個網站執行此操作:

RewriteEngine On
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI}

但是有沒有辦法為網站的一個頁面做到這一點?例如“www.example.com/protected-page”

答案1

嘗試這個

RewriteRule ^/protected-page/(.*) https://example.com/protected-page/$1 [R,L]

參考 :http://httpd.apache.org/docs/current/rewrite/intro.html

答案2

我最終做了一些不同的事情,並確保了一切如果頁面受到保護則無法正常運作:

  RewriteEngine On
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteCond %{REQUEST_URI} !^(.*loadFormImages.*)
  RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [L]
  #RewriteLog /opt/tmp/rewrite.log
  #RewriteLogLevel 3

相關內容