Проблема с mod_rewrite

2354570

Мне нужно, чтобы при обращении к домену, в момент переадресации на index.php корневого каталога, заодно приписывался и параметр section=1.
То есть: http://www.domen.com -> http://www.domen.com/index.php?section=1
Я это прописал в .htaccess вот так, но оно не срабатывает. Где баг?
 
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/$ /index.php?section=1 [L]
</IfModule>

ghytr00013

Насколько я помню, в .htaccess такие вещи не прописываются, надо прописывать в httpd.conf.
А чем мешает в index.php смотреть, пришел ли параметр section, (или запрошеный url сверять). Если не пришел - устанавливаем section=1. Или уж, если так необходима переадресация, header("Location:...").

artimon

Попробуй
RewriteRule ^$

Note: Never forget that Pattern is applied to a complete URL in per-server configuration files. But in per-directory configuration files, the per-directory prefix (which always is the same for a specific directory!) is automatically removed for the pattern matching and automatically added after the substitution has been done. This feature is essential for many sorts of rewriting, because without this prefix stripping you have to match the parent directory which is not always possible.

2354570

Насколько я помню, в .htaccess такие вещи не прописываются, надо прописывать в httpd.conf.
Ещё как прописываются.
В index.php лезть - неконцептуально.

ghytr00013

Ну не знаю... Я когда возился с этим, возникли какие-то проблемы, решилось прописыванием в httpd.conf. А вообще:
Unbelievably mod_rewrite provides URL manipulations in per-directory context, i.e., within .htaccess files, although these are reached a very long time after the URLs have been translated to filenames. It has to be this way because .htaccess files live in the filesystem, so processing has already reached this stage. In other words: According to the API phases at this time it is too late for any URL manipulations. To overcome this chicken and egg problem mod_rewrite uses a trick: When you manipulate a URL/filename in per-directory context mod_rewrite first rewrites the filename back to its corresponding URL (which is usually impossible, but see the RewriteBase directive below for the trick to achieve this) and then initiates a new internal sub-request with the new URL. This restarts processing of the API phases.
Оставить комментарий
Имя или ник:
Комментарий: