Задать вопрос
Ответы пользователя по тегу htaccess
  • Почему не работают примеры mod_rewrite?

    @dodo512
    RewriteRule "^/foo$" "/bar"

    Вполне рабочее правило в контексте VirtualHost, но для Directory и .htaccess оно не походит.
    В контексте VirtualHost строка с которой работает RewriteRule всегда начинается с /
    В контексте .htaccess строка с которой работает RewriteRule не начинается с /

    Эти отличия в зависимости от того, где определена директива RewriteRule описаны документации.
    httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rew...
    In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html"). This is the (%-decoded) URL-path.

    In per-directory context (Directory and .htaccess), the Pattern is matched against only a partial path, for example a request of "/app1/index.html" may result in comparison against "app1/index.html" or "index.html" depending on where the RewriteRule is defined.


    Ещё этот момент хорошо изложен в статье https://habr.com/company/sprinthost/blog/129560/
    Ответ написан
    Комментировать