2014-01-16 67 views
1

我正在尋找一種方法來啓用一些IP或主機名的基礎上的一些.htaccess規則(希望與正則表達式)。這是所有的stackoverflow,但我找不到任何通用規則適用於一個規則塊(實際上,這可能不是如何.htaccess工作,我不知道!)。.htaccess規則IP地址

我不需要重寫規則。我不需要訪問/拒絕標誌。我只想更改一些PHP標誌和文件行爲,以便在我們的一些服務器上使用某些開發IP地址。

例如,啓用調試模式/ error_log中/

<magical_ip_filter_tag "123.456.78.901"> 
    php_flag display_startup_errors on 
    php_flag display_errors on 
    php_flag html_errors on 
    php_flag log_errors on 
    php_value error_log /home/path/public_html/domain/PHP_errors.log 
</magical_ip_filter_tag> 

注意,我不需要爲PHP調試一個PHP的解決方案,這僅僅是一個例子。

+0

你的Apache版本是什麼? – anubhava

+0

[htaccess打開php標誌如果某些IP地址可能重複](http://stackoverflow.com/questions/3052411/htaccess-turn-on-php-flags-if-certain-ip-address) –

+0

Apache v2。 2.22,@JimLewis我無法從搜索中找到這樣的問題,謝謝。雖然答案並不特別我所希望的,但我想可能實際上並沒有答案。 –

回答

1

你通常會發現許多評論/帖子,說這是不可能的。在較新的Apache版本(2.4及更新版本)中,這可能會很容易。

但是在舊的Apache 2.2*這是我用過的變通解決

  1. 創建的/index.php一個符號鏈接,並將其命名爲像/myinde.php使用這個命令:

    ln -s index.php myindex.php 
    
  2. 添加您的代碼在您的DocumentRoot/.htaccess

    RewriteCond %{REMOTE_ADDR} ^123\.456\.78\.901$ 
    RewriteRule !^myindex.php/ myindex.php%{REQUEST_URI} [L] 
    
    <Files myindex.php> 
        php_flag display_startup_errors on 
        php_flag display_errors on 
        php_flag html_errors on 
        php_flag log_errors on 
        php_value error_log /home/path/public_html/domain/PHP_errors.log 
    </Files> 
    

RewriteRule在上面轉發您的IP地址的所有請求/myindex.php使原來的URI可以作爲PATH_INFO

Then <Files myindex.php>中的代碼塊被執行文件myindex.php

+0

你的意思是'ln -s'而不是'ls -n'來創建一個symoblic鏈接?我在這裏看到了解決方法,將用戶帶到普通用戶無法訪問的頁面,然後檢查他們是否訪問該頁面。但是,這會取代正常index.php的功能嗎?或者我應該重新從myindex.php中包含標準的index.php? –

+1

對不起,我的意思是'ln -s'。不,你不需要包含'index.php',因爲'myindex.php'只是'index.php'的符號鏈接。 – anubhava

+1

哦,我明白了!我不清楚什麼是符號鏈接。 「符號鏈接是一種特殊類型的文件,其中包含對另一個文件的引用」。聽起來像這將是一個很好的解決方法。這太糟糕了,它需要一個serverside命令,但至少對我來說,這不是問題。謝謝! –