0

Сайт на самописном php фреймворке. Все файлы самого сайта находятся в папке public. Соответственно получается 2 .htaccess файла. Структура httdocs https://prnt.sc/sli4y0 Вот так выглядит .htaccess в httpdocs https://prnt.sc/sli580 Видно что нас редиректит ко фронтенд файлам в /public В паблике тоже есть свой .htaccess (второй), ниже код

AddDefaultCharset UTF-8

Options -Indexes
DirectorySlash Off

RewriteEngine On



#Http redirect with www
#RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#Http redirect without www
#RewriteCond %{HTTP_HOST} !^www\.(.*) [NC]
#RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

#Https redirect with www
#RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
#RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

#Https redirect without www
#RewriteCond %{HTTP_HOST} !^www\.(.*) [NC]
#RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]

# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.

RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}_system42.php [NC,L]

Проблема заключается в том, что на сайт можно попасть через http, стандартные решения не работают, как правильно сделать редирект в данном случае?

1 ответ 1

1

пропишите редирект в настройках виртуалхоста. в /etc/apache2/sites-enabled/mysite.com.conf

<VirtualHost 192.168.1.1:80>
# редирект с http на https
Redirect / https://mysite.com/
</VirtualHost>

<VirtualHost 192.168.1.1:443>
# тут ваш https
</VirtualHost>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.