Получение 404 для определенного правила перезаписи URL

Я изучил и написал некоторые .htaccessправила, и некоторые из них выполняются отлично. Но есть несколько, которые не выполняются и показаны ошибки или 404

Таковы правила

RewriteEngine on

# index.php?store=xyz (executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteRule /?index.php$ /%1 [END,R=301]

RewriteRule ^/?([a-zA-Z0-9]+)$ index.php?store=

I have learnt and written some .htaccess rules and some are executing perfectly. But there are few that are not getting executed and shown error or 404

These are the rules

RewriteEngine on

# index.php?store=xyz (executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteRule /?index.php$ /%1 [END,R=301]

RewriteRule ^/?([a-zA-Z0-9]+)$ index.php?store=$1 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products$ index.php?store=$1&view=products [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=products&category=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=sales&sale=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=$1&view=single&product=$2 [END]

# index.php?store=xyz&view=products(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteRule /?index.php$ /%1/products [END,R=301]

# index.php?store=xyz&view=products&category=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteCond %{QUERY_STRING} category=([^&]+)&?
RewriteRule /?index.php$ /%1/products/%3 [END,R=301]

# index.php?store=xyz&view=sales (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteRule /?index.php$ /%1/sales [END,R=301]

# index.php?store=xyz&view=sales&sale=123 (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteCond %{QUERY_STRING} sale=([^&]+)&?
RewriteRule /?index.php$ /%1/sales/%3 [END,R=301]

# index.php?store=xyz&view=single&product=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=single&?
RewriteCond %{QUERY_STRING} product=([^&]+)&?
RewriteRule /?index.php$ /%1/single/%3 [END,R=301]

Can you please tell me what I may be doing wrong?

[END]
RewriteRule ^/?([a-zA-Z0-9]+)/products$ index.php?store=

I have learnt and written some .htaccess rules and some are executing perfectly. But there are few that are not getting executed and shown error or 404

These are the rules

RewriteEngine on

# index.php?store=xyz (executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteRule /?index.php$ /%1 [END,R=301]

RewriteRule ^/?([a-zA-Z0-9]+)$ index.php?store=$1 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products$ index.php?store=$1&view=products [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=products&category=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=sales&sale=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=$1&view=single&product=$2 [END]

# index.php?store=xyz&view=products(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteRule /?index.php$ /%1/products [END,R=301]

# index.php?store=xyz&view=products&category=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteCond %{QUERY_STRING} category=([^&]+)&?
RewriteRule /?index.php$ /%1/products/%3 [END,R=301]

# index.php?store=xyz&view=sales (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteRule /?index.php$ /%1/sales [END,R=301]

# index.php?store=xyz&view=sales&sale=123 (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteCond %{QUERY_STRING} sale=([^&]+)&?
RewriteRule /?index.php$ /%1/sales/%3 [END,R=301]

# index.php?store=xyz&view=single&product=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=single&?
RewriteCond %{QUERY_STRING} product=([^&]+)&?
RewriteRule /?index.php$ /%1/single/%3 [END,R=301]

Can you please tell me what I may be doing wrong?

&view=products [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=

I have learnt and written some .htaccess rules and some are executing perfectly. But there are few that are not getting executed and shown error or 404

These are the rules

RewriteEngine on

# index.php?store=xyz (executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteRule /?index.php$ /%1 [END,R=301]

RewriteRule ^/?([a-zA-Z0-9]+)$ index.php?store=$1 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products$ index.php?store=$1&view=products [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=products&category=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=sales&sale=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=$1&view=single&product=$2 [END]

# index.php?store=xyz&view=products(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteRule /?index.php$ /%1/products [END,R=301]

# index.php?store=xyz&view=products&category=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteCond %{QUERY_STRING} category=([^&]+)&?
RewriteRule /?index.php$ /%1/products/%3 [END,R=301]

# index.php?store=xyz&view=sales (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteRule /?index.php$ /%1/sales [END,R=301]

# index.php?store=xyz&view=sales&sale=123 (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteCond %{QUERY_STRING} sale=([^&]+)&?
RewriteRule /?index.php$ /%1/sales/%3 [END,R=301]

# index.php?store=xyz&view=single&product=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=single&?
RewriteCond %{QUERY_STRING} product=([^&]+)&?
RewriteRule /?index.php$ /%1/single/%3 [END,R=301]

Can you please tell me what I may be doing wrong?

&view=products&category= [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=

I have learnt and written some .htaccess rules and some are executing perfectly. But there are few that are not getting executed and shown error or 404

These are the rules

RewriteEngine on

# index.php?store=xyz (executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteRule /?index.php$ /%1 [END,R=301]

RewriteRule ^/?([a-zA-Z0-9]+)$ index.php?store=$1 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products$ index.php?store=$1&view=products [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=products&category=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=sales&sale=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=$1&view=single&product=$2 [END]

# index.php?store=xyz&view=products(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteRule /?index.php$ /%1/products [END,R=301]

# index.php?store=xyz&view=products&category=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteCond %{QUERY_STRING} category=([^&]+)&?
RewriteRule /?index.php$ /%1/products/%3 [END,R=301]

# index.php?store=xyz&view=sales (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteRule /?index.php$ /%1/sales [END,R=301]

# index.php?store=xyz&view=sales&sale=123 (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteCond %{QUERY_STRING} sale=([^&]+)&?
RewriteRule /?index.php$ /%1/sales/%3 [END,R=301]

# index.php?store=xyz&view=single&product=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=single&?
RewriteCond %{QUERY_STRING} product=([^&]+)&?
RewriteRule /?index.php$ /%1/single/%3 [END,R=301]

Can you please tell me what I may be doing wrong?

&view=sales&sale= [END]
RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=

I have learnt and written some .htaccess rules and some are executing perfectly. But there are few that are not getting executed and shown error or 404

These are the rules

RewriteEngine on

# index.php?store=xyz (executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteRule /?index.php$ /%1 [END,R=301]

RewriteRule ^/?([a-zA-Z0-9]+)$ index.php?store=$1 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products$ index.php?store=$1&view=products [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=products&category=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=sales&sale=$2 [END]
RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=$1&view=single&product=$2 [END]

# index.php?store=xyz&view=products(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteRule /?index.php$ /%1/products [END,R=301]

# index.php?store=xyz&view=products&category=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteCond %{QUERY_STRING} category=([^&]+)&?
RewriteRule /?index.php$ /%1/products/%3 [END,R=301]

# index.php?store=xyz&view=sales (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteRule /?index.php$ /%1/sales [END,R=301]

# index.php?store=xyz&view=sales&sale=123 (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteCond %{QUERY_STRING} sale=([^&]+)&?
RewriteRule /?index.php$ /%1/sales/%3 [END,R=301]

# index.php?store=xyz&view=single&product=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=single&?
RewriteCond %{QUERY_STRING} product=([^&]+)&?
RewriteRule /?index.php$ /%1/single/%3 [END,R=301]

Can you please tell me what I may be doing wrong?

&view=single&product= [END]

# index.php?store=xyz&view=products(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteRule /?index.php$ /%1/products [END,R=301]

# index.php?store=xyz&view=products&category=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=products&?
RewriteCond %{QUERY_STRING} category=([^&]+)&?
RewriteRule /?index.php$ /%1/products/%3 [END,R=301]

# index.php?store=xyz&view=sales (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteRule /?index.php$ /%1/sales [END,R=301]

# index.php?store=xyz&view=sales&sale=123 (error 404)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=sales&?
RewriteCond %{QUERY_STRING} sale=([^&]+)&?
RewriteRule /?index.php$ /%1/sales/%3 [END,R=301]

# index.php?store=xyz&view=single&product=123(executing perfectly)
RewriteCond %{QUERY_STRING} store=([^&]+)&?
RewriteCond %{QUERY_STRING} view=single&?
RewriteCond %{QUERY_STRING} product=([^&]+)&?
RewriteRule /?index.php$ /%1/single/%3 [END,R=301]

Скажите, пожалуйста, что я делаю не так?

1 ответ

  1. Перенаправление клиента из

    индекс.php?store=xyz & view=single&product=123

    к

    / %1 / одиночный / %3

    и у вас есть соответствующий RewriteRule

    RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=
    	

    You redirect the client from

    index.php?store=xyz&view=single&product=123

    to

    /%1/single/%3

    and you have a corresponding RewriteRule

    RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=$1&view=single&product=$2 [END]
    

    You also redirect the client from

    index.php?store=xyz&view=sales&sale=123

    to

    /%1/sales/%3

    but there is no corresponding RewriteRule, only two

    RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=products&category=$2 [END]
    RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=sales&sale=$2 [END]
    

    So maybe changing one of the "product" rules to "sales" fixes your immediate problem.


    Although, you should be aware that the redirecting rules don't do, what you might think.

    RewriteCond %{QUERY_STRING} store=([^&]+)&?
    RewriteCond %{QUERY_STRING} view=single&?
    RewriteCond %{QUERY_STRING} product=([^&]+)&?
    RewriteRule /?index.php$ /%1/single/%3 [END,R=301]
    

    Having three RewriteCond, don't correspond to %1 and %3 in your rewrite rule, only %1 is valid, see RewriteRule for an explanation

    In addition to plain text, the Substitution string can include

    1. ...

    2. back-references (%N) to the last matched RewriteCond pattern

    To have both %1 and %3, you must capture three parts in the last RewriteCond, e.g.

    RewriteCond %{QUERY_STRING} store=([^&]+)&view=(single)&product=([^&]+)
    RewriteRule ...
    

    See another answer to RewriteCond to match query string parameters in any order for a solution to capture multiple parts.

    &view=single&product= [END]


    Вы также перенаправить клиента от

    индекс.php?store=xyz & view=sales & sale=123

    к

    / % 1/продажи / %3

    но нет соответствующихRewriteRule, только два

    RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=
    	

    You redirect the client from

    index.php?store=xyz&view=single&product=123

    to

    /%1/single/%3

    and you have a corresponding RewriteRule

    RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=$1&view=single&product=$2 [END]
    

    You also redirect the client from

    index.php?store=xyz&view=sales&sale=123

    to

    /%1/sales/%3

    but there is no corresponding RewriteRule, only two

    RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=products&category=$2 [END]
    RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=sales&sale=$2 [END]
    

    So maybe changing one of the "product" rules to "sales" fixes your immediate problem.


    Although, you should be aware that the redirecting rules don't do, what you might think.

    RewriteCond %{QUERY_STRING} store=([^&]+)&?
    RewriteCond %{QUERY_STRING} view=single&?
    RewriteCond %{QUERY_STRING} product=([^&]+)&?
    RewriteRule /?index.php$ /%1/single/%3 [END,R=301]
    

    Having three RewriteCond, don't correspond to %1 and %3 in your rewrite rule, only %1 is valid, see RewriteRule for an explanation

    In addition to plain text, the Substitution string can include

    1. ...

    2. back-references (%N) to the last matched RewriteCond pattern

    To have both %1 and %3, you must capture three parts in the last RewriteCond, e.g.

    RewriteCond %{QUERY_STRING} store=([^&]+)&view=(single)&product=([^&]+)
    RewriteRule ...
    

    See another answer to RewriteCond to match query string parameters in any order for a solution to capture multiple parts.

    &view=products&category= [END]
    RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=

    You redirect the client from

    index.php?store=xyz&view=single&product=123

    to

    /%1/single/%3

    and you have a corresponding RewriteRule

    RewriteRule ^/?([a-zA-Z0-9]+)/single/([0-9]+)$ index.php?store=$1&view=single&product=$2 [END]
    

    You also redirect the client from

    index.php?store=xyz&view=sales&sale=123

    to

    /%1/sales/%3

    but there is no corresponding RewriteRule, only two

    RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=products&category=$2 [END]
    RewriteRule ^/?([a-zA-Z0-9]+)/products/([0-9]+)$ index.php?store=$1&view=sales&sale=$2 [END]
    

    So maybe changing one of the "product" rules to "sales" fixes your immediate problem.


    Although, you should be aware that the redirecting rules don't do, what you might think.

    RewriteCond %{QUERY_STRING} store=([^&]+)&?
    RewriteCond %{QUERY_STRING} view=single&?
    RewriteCond %{QUERY_STRING} product=([^&]+)&?
    RewriteRule /?index.php$ /%1/single/%3 [END,R=301]
    

    Having three RewriteCond, don't correspond to %1 and %3 in your rewrite rule, only %1 is valid, see RewriteRule for an explanation

    In addition to plain text, the Substitution string can include

    1. ...

    2. back-references (%N) to the last matched RewriteCond pattern

    To have both %1 and %3, you must capture three parts in the last RewriteCond, e.g.

    RewriteCond %{QUERY_STRING} store=([^&]+)&view=(single)&product=([^&]+)
    RewriteRule ...
    

    See another answer to RewriteCond to match query string parameters in any order for a solution to capture multiple parts.

    &view=sales&sale= [END]

    Поэтому, возможно, изменение одного из правил» продукта «на» продажи » исправит вашу непосредственную проблему.


    Хотя, вы должны знать, что правила перенаправления не делают, что вы можете подумать.

    RewriteCond %{QUERY_STRING} store=([^&]+)&?
    RewriteCond %{QUERY_STRING} view=single&?
    RewriteCond %{QUERY_STRING} product=([^&]+)&?
    RewriteRule /?index.php$ /%1/single/%3 [END,R=301]
    

    Имея триRewriteCond, не соответствуют %1и %3в вашем правиле перезаписи, только %1допустимо, см. RewriteRuleобъяснение

    В дополнение к обычному тексту строка подстановки может включать

    1. обратные ссылки (%N) на последний согласованный шаблон перезаписи

    Чтобы иметь и %1то и %3другое , вы должны захватить три части в последнейRewriteCond, например

    RewriteCond %{QUERY_STRING} store=([^&]+)&view=(single)&product=([^&]+)
    RewriteRule ...
    

    См. другой ответ на RewriteCond для сопоставления параметров строки запроса в любом порядке для решения для захвата нескольких частей.