P
P
Pavel Sidorov2021-08-09 14:21:53
htaccess
Pavel Sidorov, 2021-08-09 14:21:53

How to move to a new 301 redirect domain?

The site is currently available at two locations. Two domains refer to the same folder, respectively, and the base on the host
How to redirect all pages to the same ones only on the new domain. Posted the code.

The page returned "too many redirects"

RewriteEngine On
RewriteRule ^(.*)$ https://new-domain.ru/$1 [R=301,L]


Options -Indexes 
ErrorDocument 404 /404.php


<IfModule mod_rewrite.c>


  Options +FollowSymLinks
  RewriteEngine On

  RewriteRule ^([^.]*[^/])$ https://old-domain.ru/$1/ [R=301,L]

  RewriteCond %{THE_REQUEST}  " /index\.(php|html)"
  RewriteRule ^index\.(php|html) https://old-domain.ru/ [R=301,L]

  RewriteCond %{HTTPS}       !=on     [OR]
  RewriteCond %{THE_REQUEST} ^[^?]+// [OR]
  RewriteCond %{HTTP_HOST}   ^www\.   [NC]
  RewriteRule ^(.*)$ https://old-domain.ru/$1 [R=301,L]
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$
  RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
  RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]

</IfModule>

<IfModule mod_dir.c>
  DirectoryIndex index.php index.html
</IfModule>

<IfModule mod_expires.c>
  ExpiresActive on
  ExpiresByType image/jpeg "access plus 3 day"
  ExpiresByType image/gif "access plus 3 day"
</IfModule>


# сжатие text, html, javascript, css, xml:
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>
 
# кеш браузера
<ifModule mod_expires.c>
ExpiresActive On
 
#по умолчанию кеш в 5 секунд
ExpiresDefault "access plus 1 days"
 
# Включаем кэширование изображений и флэш на месяц
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType image/jpeg "access plus 4 weeks"
ExpiresByType image/png "access plus 30 days"
ExpiresByType image/gif "access plus 43829 minutes"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
 
# Включаем кэширование css, javascript и текстовых файлоф на одну неделю
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 604800 seconds"
ExpiresByType application/javascript "access plus 604800 seconds"
ExpiresByType application/x-javascript "access plus 604800 seconds"
 
# Включаем кэширование html и htm файлов на один день
ExpiresByType text/html "access plus 43200 seconds"
 
# Включаем кэширование xml файлов на десять минут
ExpiresByType application/xhtml+xml "access plus 600 seconds"
 
# Нестандартные шрифты сайта 
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
</ifModule>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-08-09
@pavel__sidorov

The page returned "too many redirects"
RewriteEngine On
RewriteRule ^(.*)$ https://new-domain.ru/$1 [R=301,L]

If two domains refer to the same folder, then you need to add the check %{HTTP_HOST}
RewriteEngine On
RewriteCond %{HTTP_HOST}  ^(www\.)?old-domain\.ru$  [NC]
RewriteRule ^(.*)$ https://new-domain.ru/$1 [R=301,L]

And in the rest of the RewriteRule replace https://old-domain.ruwithhttps://new-domain.ru

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question