是否可以在<if>指令中进行条件接受语言重定向?

时间:2019-03-06 18:17:46

标签: apache .htaccess url-redirection apache2.4

我想实现什么?

如果要调用主页(/de/)并且HTTP标头/以访问者浏览器的Accept-Language开头,但仅针对特定域,我想重定向到de

这是我的出发点:

由于我有许多特定于域的重定向规则,所以我有多个<If>指令。以下代码段已降至最低。

<IfModule mod_rewrite.c>
    RewriteEngine on

    # Redirect serveral domain aliases
    RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^(www\.)?my\-domain\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^(www\.)?anotherdomain\.com$
    RewriteRule .* https://www.mywebsite.com/en/products/overview/ [R=301,L]

    RewriteCond %{HTTP_HOST} ^(karriere|jobs)\.areal\-domain.at$
    RewriteRule .* https://www.mywebsite.com/de/ueber-uns/karriere/ [R=301,L]

    # Redirect language DE for homepage only of www.mywebsite.com
    # (the following rule is  outside of the following otherwise it will not work actually
    RewriteCond %{REQUEST_URI} ^/?$
    RewriteCond %{HTTP:Accept-Language} ^de [NC]
    RewriteRule ^$ /de/ [R=301,QSA,L]

    <If "req('Host') =~ /(live.mywebsite.com|www.mywebsite.com|mywebsite.com|mywebsite.docker)/">
        RedirectMatch 301 ^/$ /en/
        RedirectMatch 301 ^/contact(/)?$ /en/about-us/contact/
        RedirectMatch 301 ^/customer-support(/)?$ /en/service-and-support/
    </If>

</IfModule>

这是我的问题:

如果我将对语言重定向的重写放入<If>指令中,则apache v2.4.38服务器始终会发送HTTP状态代码500,如下面的代码片段所示:

<IfModule mod_rewrite.c>
    RewriteEngine on

    # ...

    <If "req('Host') =~ /(live.mywebsite.com|www.mywebsite.com|mywebsite.com|mywebsite.docker)/">
        # Redirect language DE for homepage only of www.mywebsite.com
        RewriteCond %{REQUEST_URI} ^/?$
        RewriteCond %{HTTP:Accept-Language} ^de [NC]
        RewriteRule ^$ /de/ [R=301,QSA,L]

        RedirectMatch 301 ^/$ /en/
        RedirectMatch 301 ^/contact(/)?$ /en/about-us/contact/
        RedirectMatch 301 ^/customer-support(/)?$ /en/service-and-support/
    </If>

</IfModule>

这种行为的原因是什么?

我阅读了文档,但是找不到有关我的情况的任何信息。

0 个答案:

没有答案