LINUX.ORG.RU
ФорумAdmin

mod_rewrite сайт в папку

 ,


0

1

Всем доброго времени.

Сломал голову, пожалуйста помогите с задачей... Бьюсь уже около года, все время сдаваясь и не находя все же решение, оставляю вид site.ru/dir

Четкая задача: есть сайт site.ru, но на хосте (хост свой, рулить могу как хочу), на хосте корневой .htaccess и много папок с сайтами (dir1, dir2, ...) Если делать стандартное перенаправление, вид URL в строке адреса получается site.ru/папка/, а мне нужно чтобы вид URL остался site.ru/

Получилось сделать только на одном из папок сайта, на субдомене, делаю так:

RewriteCond %{REQUEST_URI} !^/dir1
RewriteCond %{HTTP_HOST} ^sub.site.com$ [NC]
RewriteRule ^(.*)$ /dir1/$1 [L,QSA]

===> Результат правила выше, вот такой: при запросе sub.site.com получаем sub.site.com и все ресурсы сайта из папки dir1

RewriteCond %{REQUEST_URI} !\/site
RewriteCond %{HTTP_HOST} ^site.ru$ [NC]
RewriteRule ^(.*)$ dir2/$2 [L]

===> Результат правила выше, вот такой: при запросе site.ru получаем site.ru, но ТОЛЬКО начальную страницу index.html, прочие ресурсы сайта из папки dir2 НЕ ГРУЗЯТСЯ! Если делать RewriteRule ^(.*)$ dir2/$1 [L], сайт совсем не грузится, вечная загрузка, видимо зацикливание по /dir2/dir2/dir2/dir2/...

Прошу, пожалуйста помогите, кто точно знает, как сделать тоже самое но не для субдомена, а для сайта? Заранее БОЛЬШОЕ БОЛЬШОЕ СПАСИБО!!!

---

Как насчет такого, можно это как то использовать и как апач будет рулить по именам:

<VirtualHost *:80>
    ServerName first.ru
    ServerAlias [url]www.first.ru[/url]
    DocumentRoot /var/www/vhosts/first.ru/httpdocs
    ErrorLog logs/first.ru-error.log
</VirtualHost>
 
<VirtualHost *:80>
    ServerName second.ru
    ServerAlias [url]www.second.ru[/url]
    DocumentRoot /var/www/vhosts/second.ru/httpdocs
    ErrorLog logs/second.ru-error.log
</VirtualHost>



Последнее исправление: alexpebody (всего исправлений: 4)

Не получается, похоже только mod-rewrite

Собственно результаты, прописал я второй виртуалхост вот так (потому как *:80 это походу и есть дефолт):

<VirtualHost site.ru:80> ServerName site.ru ServerAlias http://www.site.ru DocumentRoot /var/www/site2 ErrorLog logs/first.ru-error.log </VirtualHost>

И, как я и считал, URL в строке адреса выглядит точно так же как и при простом mod_rewrite, а именно: site.ru/dir1/, а нужно вот так: site.ru/

alexpebody
() автор топика

не работает!

К сожалению вот такой конфиг не работает:

<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName http://www.example.com

#ServerAdmin it@prodsib.com #DocumentRoot /var/www/html DocumentRoot /var/www

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with «a2disconf». #Include conf-available/serve-cgi-bin.conf </VirtualHost>

<VirtualHost sub.site.com> ServerName sub.site.com ServerAlias http://www.sub.site.com DocumentRoot /var/www/site ErrorLog ${APACHE_LOG_DIR}/box_error.log CustomLog ${APACHE_LOG_DIR}/box_access.log combined </VirtualHost>

Никак! В строке адреса URL браузера: http://sub.site.com выводит index.php корня site.com и все! Что только не крутил, толку 0 не выводит субдомен!

alexpebody
() автор топика
Ответ на: не работает! от alexpebody

ОМГ, все много проще вот так заработало, ну почему же нигде нет нормальной документации В МЕЛОЧАХ?!

<VirtualHost *:80> ServerName sub.site.com ServerAlias www[dot]sub[dot]site[dot]com DocumentRoot /var/www/site ErrorLog ${APACHE_LOG_DIR}/box_error.log CustomLog ${APACHE_LOG_DIR}/box_access.log combined </VirtualHost>

alexpebody
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.