LINUX.ORG.RU
решено ФорумAdmin

.htaccess не работает с www

 , ,


0

1

привет.

centOS 7, apache2, редиректы из .htaccess не работают, если заходить на сайт через www. Важно знать след. моменты:

1. используется https

2. без www все OK

3. mod_rewrite установлен и работает корректно, судя по всему .htaccess вообще не читается

4. конфига httpd (443):

<VirtualHost *:443>
	ServerName domain.com.au
	ServerAlias www.domain.com.au

	SSLProtocol all -SSLv3 -SSLv2
	SSLHonorCipherOrder on
	SSLCipherSuite *****

	SSLEngine on
	SSLCertificateFile *****
	SSLCertificateKeyFile *****
	SSLCACertificateFile *****
	<Directory /home/domain.com.au/www>
		Options FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
	DocumentRoot /home/domain.com.au/www
 </VirtualHost> 

80 порт, на всякий случай:

<VirtualHost *:80>
	ServerName domain.com.au
	ServerAlias www.domain.com.au
    CustomLog /home/domain.com.au/logs/access.log common
	DocumentRoot /home/domain.com.au/www
    ErrorLog /home/domain.com.au/logs/error.log
	ServerAdmin nick@domain.com.au

	AddType application/x-httpd-php .php .php3 .php4 .php5 .phtml
	AddType application/x-httpd-php-source .phps

	<Directory /home/domain.com.au/www>
		Options FollowSymLinks
		AllowOverride All
		Require all granted
	</Directory>
</VirtualHost> 

Буду благодарен за помощь



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

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

.htaccess

Я уже говорил, что судя по всему .htaccess вообще не воспринимается, тем не менее привожу код из него.

Без www все что есть в .htaccess корректно работает.

DirectoryIndex index.php
RewriteEngine On
 
Options +FollowSymlinks

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteCond %{REQUEST_URI} !/customers
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]


Redirect 301 /Web-Development/Blog/ http://domain.com.au/Cloud-IT-Blog/
Redirect 301 /Bookkeeping/Services-Brisbane/ http://domain.com.au/Service/Bookkeeping/
Redirect 301 /Bookkeeping/Services-Brisbane/Request-a-Quote/ http://domain.com.au/Service/Bookkeeping/
Redirect 301 /Bookkeeping/About-Us/ http://domain.com.au/About/Management/
Redirect 301 /Bookkeeping/About-Us/Our-People/ http://domain.com.au/About/Management/
Redirect 301 /Bookkeeping/Services-Brisbane/Cloud-Based-Bookkeeping/ http://domain.com.au/Service/Xero/
Redirect 301 /Web-Development/About-Us/ http://domain.com.au/About/Management/
Redirect 301 /Web-Development/Services-Brisbane/ http://domain.com.au/Service/Software-Development/
Redirect 301 /Web-Development/Services-Brisbane/Business-IT-Solutions/ http://domain.com.au/Service/Google-apps/
Redirect 301 /Web-Development/Services-Brisbane/Bookkeeping-Integration/ http://domain.com.au/Service/Bookkeeping/
Redirect 301 /Web-Development/ http://domain.com.au/Service/Web-Development/
Redirect 301 /Bookkeeping/Services/ http://domain.com.au/Bookkeeping-Brisbane/
Redirect 301 /Bookkeeping/services-brisbane/ http://domain.com.au/Bookkeeping-Brisbane/
Redirect 301 /Web-Development/ http://domain.com.au/Service/Web-Development/

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

<IfModule mod_expires.c>
	ExpiresActive On
	ExpiresDefault "access 7 days"
	ExpiresByType application/javascript "access plus 1 year"
	ExpiresByType text/javascript "access plus 1 year"
	ExpiresByType text/css "access plus 1 year"
	ExpiresByType text/html "access plus 7 day"
	ExpiresByType text/x-javascript "access 1 year"
	ExpiresByType image/gif "access plus 1 year"
	ExpiresByType image/jpeg "access plus 1 year"
	ExpiresByType image/png "access plus 1 year"
	ExpiresByType image/jpg "access plus 1 year"
	ExpiresByType image/x-icon "access 1 year"
	ExpiresByType application/x-shockwave-flash "access 1 year"

	<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|css|swf|js)$">
		Header set Cache-Control "max-age=604800, public"
	</FilesMatch>
</IfModule>

## ENABLE COMPRESSION ##
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype

# For Olders Browsers Which Can't Handle Compression
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
## ENABLE COMPRESSION ##
imaxegorov
() автор топика
Ответ на: .htaccess от imaxegorov

А что будет, если все эти «RewriteEngine On - RewriteRule» явно отдать модулю, который у вас работает (mod_rewrite), а редиректы, не отдавать? Ну, как-нибудь так:

<IfModule mod_rewrite.c>
  Options +FollowSymLinks
  RewriteEngine On
...
</IfModule>
...
...
Redirect 301 /...
...

LaLe
()
Ответ на: комментарий от imaxegorov

«Подгружается» htaccess или «не подгружается» можно достаточно легко проверить, добавив в него простую директиву:

Deny from all

Если сайт после этого по прежнему доступен - значит и правда, «не подгружается».

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

А вообще, давайте с простого начнем:

Что в днс для www и без www? Что в /etc/hosts на тачке с которой открываете сайт браузером?

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

Прописал. Да, действительно, сайт при заходе без www показал страницу Apache, с www сайт нормально загрузился. Стало быть, htaccess с www не работает.

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

Решено. У нас для www старый IP стоял. Спасибо за наводку.

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