簡體   English   中英

如何將 HTTP_REFERER 從 htaccess 轉發到頁面?

[英]How to forward the HTTP_REFERER to a page from htaccess?

當有人點擊我的站點根文件夾 (www.myDomain.com) 並且 Index.php 頁面得到它之后,我如何將 HTTP_REFERER 轉發到 Index.php 頁面以便我可以記錄它?

我有這個,但沒有喜悅。

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^mydomain.com [NC]
RewriteRule ^/?index.php?%{HTTP_REFERER}$ mydomain.com/ [L,R]

謝謝

確保 apache mod_rewrite 已啟用。 然后重定向:

<IfModule mod_rewrite.c>
    # Make sure url's can be rewritten.
    RewriteEngine on

    # Redirect requests that are not files or directories to index.php.
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
</IfModule>

這就是大多數 CMS 的做法。 這確實意味着如果他們將直接路徑寫入文件,他們將看到該文件。 因此,您需要在此之前添加以下內容:

# Prevent direct access to these file types.
<FilesMatch "\.(sql|md|sh|scss|rb|conf|rc|tpl(\.php)?|lib(\.php)?|wig(\.php)?|pg(\.php)?|reg(\.php)?|db(\.php)?)$">
  Require all denied
</FilesMatch>

這意味着他們無法訪問上面列出的文件擴展名。 您可以只用rc|php替換最后幾個,但我允許訪問 .php 文件沒有繼續使用 .lib,因此我可以執行受瀏覽器身份驗證保護的腳本,以進行調試和銀彈數據庫修復。

您的 apache 配置中還必須有類似的內容,允許在您的站點目錄中讀取 .htaccess。

<Directory "C:/Sites">
    AllowOverride All
</Directory>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM