×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Apache
Posted by: Ilya Kutalev
Added: Jul 10, 2016 9:39 PM
Modified: Jul 10, 2016 9:40 PM
Views: 7
Правила для htaccess, редиректы
  1. # ===== домен => www.домен =====
  2. RewriteEngine On
  3. RewriteCond %{HTTP_HOST} ^example.ru
  4. RewriteRule (.*) http://www.example.ru/$1 [R=301,L]
  5.  
  6. # ===== www.домен => домен =====
  7. RewriteEngine On
  8. RewriteCond %{HTTP_HOST} ^www.example.ru$ [NC]
  9. RewriteRule ^(.*)$ http://example.ru/$1 [R=301,L]
  10.  
  11. # ===== www.домен => домен =====
  12. RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  13. RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  14.  
  15. # ===== Удалить слеш на конце =====
  16. RewriteEngine On
  17. RewriteBase /
  18. RewriteCond %{REQUEST_URI} /$ [NC]
  19. RewriteRule ^(.*)(/)$ $1 [L,R=301]
  20.  
  21. # ===== Добавить слеш на конце =====
  22. RewriteEngine On
  23. RewriteBase /
  24. RewriteCond %{REQUEST_FILENAME} !-f
  25. RewriteCond %{REQUEST_URI} !(.*)/$
  26. RewriteRule ^(.*[^/])$ $1/ [L,R=301]