2013-07-26 41 views
0

我正在用htaccess文件掙扎。.htaccess與API_VERSION比較

我需要做的是在apache版本低於某個版本時執行重寫規則,否則就是不同的規則。

這是關於在apache 2.2.7中引入的反向引用,但我仍然需要支持較老的apache版本。

我想要做的是這樣的:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    if API_VERSION <= 2.2.6(or 20051115:5) then 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 
    else 
     RewriteCond %{REQUEST_FILENAME} !-d 
     RewriteCond %{REQUEST_FILENAME} !-f 
     RewriteRule ^(.*)$ index.php?url=$1 [QSA,L,B] 
    endif 
</IfModule> 

我需要的「B」時,它的面世,誰知道這是否可以工作或以不同的方式得到相同的結果?

回答

1

你可以試試這個:

<IfModule mod_rewrite.c> 
RewriteEngine On 

# Lexographic string match 
RewriteCond %{API_VERSION} <=20051115:5 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 

# Lexographic string match 
RewriteCond %{API_VERSION} >20051115:5 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L,B] 
</IfModule> 

或安裝mod_version和嘗試:

<IfVersion <= 2.2.6> 
    <IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] 
    </IfModule> 
</IfVersion> 
<IfVersion > 2.2.6 > 
    <IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L,B] 
    </IfModule> 
</IfVersion> 
+0

難道是因爲我不能把「 B」即使條件不匹配。 它給了我一個500錯誤 – Crazy

+0

@很有可能,我已經用替代解決方案更新了我的答案 – Jon

+0

Sweet !,就像一個魅力。我的centos 5(2.2.3)和6(2.2.15)apache安裝都預裝了mod_version並已啓用。 – Crazy