Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 在<;如果>;可能吗? 我想要实现什么?_Apache_.htaccess_Url Redirection_Apache2.4 - Fatal编程技术网

Apache 在<;如果>;可能吗? 我想要实现什么?

Apache 在<;如果>;可能吗? 我想要实现什么?,apache,.htaccess,url-redirection,apache2.4,Apache,.htaccess,Url Redirection,Apache2.4,如果调用主页(/),并且HTTP头Accept Language以访问者浏览器的de开头,但仅针对特定域,我想重定向到/de/ 以下是我的出发点: 由于我有许多特定于域的重定向规则,因此我有多个指令。下面的代码片段被缩减到最小值 <IfModule mod_rewrite.c> RewriteEngine on # Redirect serveral domain aliases RewriteCond %{HTTP_HOST} ^(www\.)?mydom

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

以下是我的出发点: 由于我有许多特定于域的重定向规则,因此我有多个
指令。下面的代码片段被缩减到最小值

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

重新启动发动机
#重定向服务器域别名
重写cond%{HTTP_HOST}^(www\)?mydomain\.com$[或]
重写cond%{HTTP_HOST}^(www\)?my \-domain\.com$[或]
重写cond%{HTTP_HOST}^(www\)?另一个域\.com$
重写规则。*https://www.mywebsite.com/en/products/overview/ [R=301,L]
重写cond%{HTTP|u HOST}^(karriere|jobs)\.areal\-domain.at$
重写规则。*https://www.mywebsite.com/de/ueber-uns/karriere/ [R=301,L]
#仅为www.mywebsite.com主页重定向语言DE
#(以下规则不属于以下规则,否则它实际上将不起作用
重写条件%{REQUEST_URI}^/$
RewriteCond%{HTTP:Accept Language}^de[NC]
重写规则^$/de/[R=301,QSA,L]
重定向匹配301^/$/en/
重定向匹配301^/联系人(/)?$/en/关于我们/联系人/
重定向匹配301^/客户支持(/)?$/en/服务和支持/
这是我的问题: 如果我将语言重定向的重写放入
指令中,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>

重新启动发动机
# ...
#仅为www.mywebsite.com主页重定向语言DE
重写条件%{REQUEST_URI}^/$
RewriteCond%{HTTP:Accept Language}^de[NC]
重写规则^$/de/[R=301,QSA,L]
重定向匹配301^/$/en/
重定向匹配301^/联系人(/)?$/en/关于我们/联系人/
重定向匹配301^/客户支持(/)?$/en/服务和支持/
这种行为的原因是什么? 我阅读了文档,但找不到有关我的场景的任何信息