LINUX.ORG.RU
ФорумAdmin

Работа mod_rewrite в Apache 2.4

 ,


0

1

Всем здравствуйте! Есть site.ru где всё работает через index.php с правилом в htaccess:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php?%{QUERY_STRING}

Захотелось чтобы login.site.ru вёл на site.ru/index.php?login, и были добавлены строки и htaccess стал таким:

RewriteCond %{HTTP_HOST} ^login\.site\.ru$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*) http://site.ru/login [P]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php?%{QUERY_STRING}

И оно прекрасно работает на CentOS 6 с апачем 2.2.15 и php 5.6.18. А вот когда я переношу это на апач 2.4, то перенаправление работать перестаёт. Я уже что-только не пробовал и много читал, но пока так и не нашёл решения. Надеюсь на чью-нибудь помощь. Спасибо. PS: интересует только правильность htaccess, использовать nginx, downgrade`ить апач и прочее в том же духе предлагать не стОит.

Ответ на: комментарий от Su_MPAK

А не пофиг ли... Впрочем да, не подумал.
Чтобы не гадать, включи подробный лог рерайта, да глянь, что там.

thesis ★★★★★
()
Ответ на: комментарий от thesis

Вот с Apache 2.2, где работает всё:

strip per-dir prefix: /home/site/html/ ->
         applying pattern '^(.*)' to uri ''
         RewriteCond: input='login.site.ru' pattern='^login\\.site\\.ru$' => matched
         RewriteCond: input='/' pattern='^/$' => matched
         rewrite '' -> 'http://site.ru/login'
         escaped URI in per-dir context for proxy, http://site.ru/login -> http://site.ru/login
         forcing proxy-throughput with http://site.ru/login
         go-ahead with proxy request proxy:http://site.ru/login [OK]
         strip per-dir prefix: /home/site/html/js/jquery-2.1.4.min.js -> js/jquery-2.1.4.min.js
         applying pattern '^(.*)' to uri 'js/jquery-2.1.4.min.js'
Ну и далее...

А вот с Apache 2.4, где работать не хочет:

init rewrite engine with requested uri /
pass through /
strip per-dir prefix: /home/site/html/ -> 
applying pattern '^(.*)' to uri ''
RewriteCond: input='login.site.ru' pattern='^login\\.site\\.ru$' => matched
RewriteCond: input='/' pattern='^/$' => matched
rewrite '' -> 'http://site.ru/login'
escaped URI in per-dir context for proxy, http://site.ru/login -> http://site.ru/login
forcing proxy-throughput with http://site.ru/login
go-ahead with proxy request proxy:http://site.ru/login [OK]
init rewrite engine with requested uri /index.html
pass through /index.html
strip per-dir prefix: /home/site/site/index.html -> index.html
applying pattern '^(.*)' to uri 'index.html'
RewriteCond: input='login.site.ru' pattern='^login\\.site\\.ru$' => matched
RewriteCond: input='/index.html' pattern='^/$' => not-matched
strip per-dir prefix: /home/site/html/index.html -> index.html
applying pattern '^(.*)' to uri 'index.html'
RewriteCond: input='/home/site/html/index.html' pattern='!-d' => matched
RewriteCond: input='/home/site/html/index.html' pattern='!-f' => matched
rewrite 'index.html' -> 'index.php?'
split uri=index.php? -> uri=index.php, args=<none>
add per-dir prefix: index.php -> /home/site/html/index.php
strip document_root prefix: /home/site/html/index.php -> /index.php
internal redirect with /index.php [INTERNAL REDIRECT]
init rewrite engine with requested uri /index.php
pass through /index.php
strip per-dir prefix: /home/site/html/index.php -> index.php
applying pattern '^(.*)' to uri 'index.php'
RewriteCond: input='login.site.ru' pattern='^login\\.site\\.ru$' => matched
RewriteCond: input='/index.php' pattern='^/$' => not-matched
strip per-dir prefix: /home/site/html/index.php -> index.php
applying pattern '^(.*)' to uri 'index.php'
RewriteCond: input='/home/site/html/index.php' pattern='!-d' => matched
RewriteCond: input='/home/site/html/index.php' pattern='!-f' => not-matched
pass through /home/site/html/index.php
init rewrite engine with requested uri /js/jquery-2.1.4.min.js, referer: http://login.site.ru/
pass through /js/jquery-2.1.4.min.js, referer: http://login.site.ru/
Начало, вроде такое же и правильное. Но потом «из ниоткуда» появляется URI=index.html и дальнейшие проверки уже идут по неправильному пути и приводят к неверному результату.

Su_MPAK
() автор топика
Ответ на: комментарий от Su_MPAK

Этот index.html берется, скорее всего, из DirectoryIndex (проверь, если не лень). Я не знаю, почему апач так делает, попробуй добавить L к первому правилу. Больше рерайтов точно нет?

thesis ★★★★★
()
Последнее исправление: thesis (всего исправлений: 1)
Ответ на: комментарий от thesis

Да, если DirectoryIndex добавить в htaccess, типа:

DirectoryIndex=login
То даже срабатывает. Но мне бы ещё пару поддоменов на другое место направить и значит DirectoryIndex не выход... Или его надо прописать на на каждый поддомен свой. Сейчас попробую... Но как-то это неправильно, по моему ))

Su_MPAK
() автор топика
Ответ на: комментарий от Su_MPAK

Я не о том, что надо «редиректить» через DirectoryIndex, у меня и в мыслях такого не было никогда, но это прикольно)
Я о том, что, видимо, после рерайта «/» апач берет документ, указанный в DirectoryIndex и повторяет обработку рерайтов, отсюда, видимо и вылезает второй прогон с /index.html. Может быть, его стоит обработать отдельно, или ВДРУГ от этого спасет [L] в RewriteRule (хотя теоретически не должен). Фиг знает, лень пробовать.

thesis ★★★★★
()
Последнее исправление: thesis (всего исправлений: 1)
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.