Pergunta

I'm struggling with a htaccess file.

What I need to do, is do a rewrite rule when the apache version is lower then a certain version, else a different rule.

This is about backreferences that were introduced in apache 2.2.7, but I still need to support older apache versions.

What I want to do is this:

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

I need the 'B' when it's available, anyone know if this can work or get the same result in a different way?

Foi útil?

Solução

You could try this:

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

Or install mod_version and try:

<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>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top