Tuckey Filter - https перенаправление

Я пытаюсь сделать 301 редирект с http на https.

Когда я использую это правило, я получаю бесконечный цикл, перенаправляющий на https://localhost/mypage:

<rule>
  <name>https redirect</name>
  <condition name="scheme" operator="notequal">^https$</condition>   
  <from>^/(.*)</from>
  <to type="permanent-redirect" last="true">https://localhost/$1</to>
</rule>

И когда я использую этот, перенаправления просто не происходит

<rule>
  <name>https redirect</name>
  <condition name="scheme" operator="equal">^http$</condition>   
  <from>^/(.*)</from>
  <to type="permanent-redirect" last="true">https://localhost/$1</to>
</rule>

Из этого я предполагаю, что мое написание условия схемы неверно, но я не могу найти правильный способ написать правило, я пробовал:

<condition name="scheme" operator="equal">^http$</condition> 
<condition name="scheme" operator="equal">http</condition> 

Любые подсказки о том, почему это не работает?


person user3673749    schedule 12.08.2014    source источник


Ответы (4)


Попробуйте с:

<rule>
  <name>https redirect</name>
  <condition name="scheme" operator="equal">http$</condition>   
  <from>^/(.*)</from>
  <to type="permanent-redirect" last="true">https://localhost/$1</to>
</rule>
person Artur    schedule 11.08.2016

Это работает:

<rule>
    <name>https redirect</name>
    <condition type="scheme" operator="notequal">https</condition>   
    <from>^/(.*)</from>
    <to type="permanent-redirect" last="true">https://yourdomain.com/$1</to>
</rule>
person Susanne Jarl    schedule 07.08.2019
comment
Не могли бы вы уточнить, почему исходный пост не работает или какую конкретную проблему вы решаете? - person P1storius; 07.08.2019
comment
Я протестировал вышеуказанное решение с текущей версией 4.0.3 фильтра перезаписи Tuckey, и оно не сработало, но это работает. - person Susanne Jarl; 08.08.2019

Я хотел бы предложить следующее

<rule>
    <name>https redirect</name>
    <condition name="scheme" operator="equal">^http$</condition>   
    <from>^/(.*)</from>
    <to type="permanent-redirect" last="true">https://localhost/$1</to>
</rule>

Я нашел указанное выше предложение в группах Google. .

Однако я использую Tuckey Filter по-разному в java-плагине. Вот как я добавляю свое правило.

    //Add https redirect for example.com
    NormalRule myruleredirect3 = new NormalRule();
    myruleredirect3.setFrom("^/(.*)");
    myruleredirect3.setTo("https://example.com/$1");
    myruleredirect3.setToType("permanent-redirect");

    //Create a Condition for this rule
    Condition myruleredirect3condition = new Condition();
    myruleredirect3condition.setName("scheme");
    myruleredirect3condition.setType("scheme");
    myruleredirect3condition.setValue("^http$");
    myruleredirect3condition.setOperator("equal");
    myruleredirect3.addCondition(myruleredirect3condition);

    //Create a Condition for this rule
    Condition myruleredirect3condition2 = new Condition();
    myruleredirect3condition2.setName("host");
    myruleredirect3condition2.setValue("example.com");
    myruleredirect3condition2.setType("header");
    myruleredirect3condition2.setOperator("equal");
    myruleredirect3.addCondition(myruleredirect3condition2);

    //Register the tuckey rewrite rule
    addRewriteRule(myruleredirect3);
person Justin Kubicek    schedule 09.06.2017

Ты можешь это сделать

Замените атрибуты scheme на header и удалите атрибут last.

<rule>
  <name>https redirect</name>
  <condition name="header" operator="notequal">^https$</condition>   
  <from>^/(.*)</from>
  <to type="permanent-redirect" >https://localhost/$1</to>
</rule>

Если проблема с циклом все еще существует, возможно, вам следует взглянуть на уровень кода в обработчике перехватчиков/фильтров, у вас могут быть условия для перенаправления туда! или по правилам уровня сервера у провайдера домена.

person shareef    schedule 22.08.2019