С www на без www
#c www на без www
RewriteCond %{HTTP_HOST} ^www.(.)$
RewriteRule ^(.)$ https://%1/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.(.)$
RewriteRule ^(.)$ https://%1/$1 [L,R=301]
С index.php на главную
#301 редирект с index.php
RewriteCond %{REQUEST_URI} /index.php
RewriteRule ^(.*)$ https://url_сайта/ [R=301,L]
RewriteCond %{REQUEST_URI} /index.php
RewriteRule ^(.*)$ https://url_сайта/ [R=301,L]
С index.html на главную
#301 редирект с index.html
RewriteRule index.html$ / [R=301,L]
RewriteRule index.html$ / [R=301,L]
С http на https
#на https://
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
С https на http
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
Обработка 404 ошибки (не всегда работает)
#404 ошибка
ErrorDocument 404 https://url_сайта/404.php
ErrorDocument 404 https://url_сайта/404.php
В случае если обработка 404 ошибки через файл .htaccess не сработает, можно воспользоваться методом описанным в этой статье.
Пример .htaccess для сайта
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# ЗАПРЕЩЁННЫЕ ФАЙЛЫ
RewriteRule .htaccess – [F]
RewriteRule template.php – [F]
# c www на без www
RewriteCond %{HTTP_HOST} ^www.(.)$
RewriteRule ^(.)$ https://%1/$1 [L,R=301]
# с index.html на главную
RewriteRule index.html$ / [R=301,L]
# на https://
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# 301 редирект с index.php
RewriteCond %{REQUEST_URI} /index.php
RewriteRule ^(.*)$ https://url_сайта.ru/ [R=301,L]
# 404 ошибка
ErrorDocument 404 https://url_сайта.ru/404.php
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# ЗАПРЕЩЁННЫЕ ФАЙЛЫ
RewriteRule .htaccess – [F]
RewriteRule template.php – [F]
# c www на без www
RewriteCond %{HTTP_HOST} ^www.(.)$
RewriteRule ^(.)$ https://%1/$1 [L,R=301]
# с index.html на главную
RewriteRule index.html$ / [R=301,L]
# на https://
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# 301 редирект с index.php
RewriteCond %{REQUEST_URI} /index.php
RewriteRule ^(.*)$ https://url_сайта.ru/ [R=301,L]
# 404 ошибка
ErrorDocument 404 https://url_сайта.ru/404.php