繁体   English   中英

.htaccess与API_VERSION进行比较

[英].htaccess comparing with API_VERSION

我正在努力使用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”字样(如果有),有人知道它是否可以工作或以不同的方式获得相同的结果吗?

您可以尝试以下方法:

<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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM