0

我正在为一个 htaccess 文件而苦苦挣扎。

我需要做的是,当 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',有人知道这是否可以工作或以不同的方式获得相同的结果?

4

1 回答 1

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>
于 2013-07-26T14:28:25.113 回答