2013-07-16 24 views
1

我運行WAMP 2.2與Apache 2.0.50和PHP 5.2.11,我看着我的phpinfo,我找不到SCRIPT_URI or SCRIPT_URL我試着將這個腳本添加到我的httpd.conf文件爲Apache和它沒有工作。任何人有任何想法SCRIPT_URI or SCRIPT_URL我的phpinfo?我需要它用於我在本地機器上運行的網站。沒有SCRIPT_URI或SCRIPT_URL在我的phpinfo

<IfModule rewrite_module> 
<IfModule headers_module> 

####### INITIAL SETUP ######################### 
    RewriteEngine on 

####### SET HEADERS ######################### 
    #get and set the host name 
     RewriteRule .* - [E=INFO_HTTP_HOST:%{HTTP_HOST},NE] 
     RequestHeader set x-orig-host "%{INFO_HTTP_HOST}e" 


    #get and set the host port 
     RewriteRule .* - [E=INFO_SERVER_PORT:%{SERVER_PORT},NE] 
     RequestHeader set x-orig-port "%{INFO_SERVER_PORT}e" 


    #If the uri starts with a slash and some alphanumerics, then make a 
    #group of that until the first non-alpha (ie. the next slash) 
     RewriteCond %{REQUEST_URI} ^(/[\w-]+) 
    #Save the content of the regex match group (%1) in an environment variable 
     RewriteRule .* - [E=INFO_REQUEST_CONTEXT:%1,NE] 
    #Set a header with the content of the environment variable 
     RequestHeader set x-orig-context "%{INFO_REQUEST_CONTEXT}e" 


    #If the accept-header contains a number after ;version= then make a regex group of that number 
     RewriteCond %{HTTP_ACCEPT} \+json;version=(\d+)$ 
    #Save the content of the regex match group (%1) in an environment variable 
     RewriteRule .* - [E=INFO_ACCEPT_VERSION:%1,NE] 
    #Set a header with the content of the environment variable 
     RequestHeader set x-orig-accept-version "%{INFO_ACCEPT_VERSION}e" 


    #If the accept-header contains kasia2. followed by some letters, 
    #then make a regex group of those letters 
     RewriteCond %{HTTP_ACCEPT} kasia2.(\w+).* 
    #Save the content of the regex match group (%1) in an environment variable 
     RewriteRule .* - [E=INFO_ACCEPT_NAME:%1,NE] 
    #Set a header with the content of the environment variable 
     RequestHeader set x-orig-accept-name "%{INFO_ACCEPT_NAME}e" 


    #If https is on ... 
     RewriteCond %{HTTPS} on 
    #...then set the protocol environment variable to "https" 
     RewriteRule .* - [E=INFO_PROTOCOL:https,NE] 
    #If https is off ... 
     RewriteCond %{HTTPS} off 
    #...then we assume it must be "http" 
     RewriteRule .* - [E=INFO_PROTOCOL:http,NE] 
    #Finally, set the protocol header 
     RequestHeader set x-orig-protocol "%{INFO_PROTOCOL}e" 


    #Get the request uri and set an environment variable 
     RewriteRule .* - [E=INFO_REQUEST_URI:%{REQUEST_URI},NE] 
    #Build the whole original url out of the available parts. SCRIPT_URI is always null, otherwise we could have used that. 
     RequestHeader set x-orig-url "%{INFO_PROTOCOL}e://%{INFO_HTTP_HOST}e%{INFO_REQUEST_URI}e" 
    #In addition make an url with only the host and context, for convenience 
     RequestHeader set x-orig-url-base "%{INFO_PROTOCOL}e://%{INFO_HTTP_HOST}e%{INFO_REQUEST_CONTEXT}e" 

</IfModule> 
</IfModule> 

是否有我必須在我的php.ini文件中執行此操作?

+0

___Apache 2.0.50 ___哇 – RiggsFolly

回答

0

新增這條線上面的腳本一起,現在,它的工作原理RewriteEngine On

+0

但是您已經在上面的腳本中使用了'RewriteEngine On'? – MrWhite

0

解決方案第一:我相信這是一個.htaccess對虛擬主機的區別。如果在.htaccess中使用RewriteRule,則會得到REDIRECT_URL集合,而如果在主apache配置中的虛擬主機中使用它們,您將得到SCRIPT_URL集合。我的解決方法是非常務實:

if(array_key_exists('SCRIPT_URL',$_SERVER)){ 
    $url = $_SERVER['SCRIPT_URL']; 
    } 
elseif(array_key_exists('REDIRECT_URL',$_SERVER)){ 
    $url = $_SERVER['REDIRECT_URL']; 
    } 
else throw...; 

背景說明:

我剛剛被比較的兩個服務器並排側,一個(薄荷16,即Ubuntu的13.10),其中REDIRECT_URL可用(和SCRIPT_URL而不是)和另一個(Ubuntu 14.04),其中REDIRECT_*變量沒有設置,但SCRIPT_URL可用於相同的信息。

他們是Apache 2.4.6與2.4.7和PHP 5.5.3-1ubuntu2.6與5.5.9-1ubuntu4.3。我只是比較phpinfo()輸出並排,除了在庫中的小版本變化,他們基本上是相同的,除了爲REDIRECT與SCRIPT $SERVER變量差異! (要徹底:薄荷16機器mcrypt的安裝位置的Ubuntu 14沒有,而Ubuntu的14已經readline的安裝,其中薄荷16機器沒有)

的最大區別在於,其中SCRIPT_URL設定在服務器具有RedirectMatch在一個虛擬主機,並在需要的腳本名稱前明確斜槓:

RewriteRule ^.*$ /main.php [NC,L] 

而所有其他的服務器我有哪裏REDIRECT_URL,而不是設置在.htaccess文件的規則,不需要那麼前進斜線:

RewriteRule ^.*$ main.php [NC,L] 

(在這兩種情況下,我都沒有明確設置RewriteBase,但the manual entry似乎表明我爲什麼不需要它,這也暗示着這種機制可能會有所不同,以至於不同的環境變量會被設置。)

+0

'SCRIPT_URL'和'SCRIPT_URL'在Apache文檔中記錄爲[由mod_rewrite維護的環境變量](http://httpd.apache.org/docs/2.2/en/mod/mod_rewrite.html#EnvVar) - 所以從它們應該存在於$ _SERVER超全局中。但是,由於某種原因,它們並不總是設定的。我有3臺服務器;他們只在其中一個上設置。 – MrWhite

相關問題