Server administration How to create redirects in .htaccess

Underground Forum

Underground Forum

  • #1

Redirects in htaccess​


301 redirect to another site:
Redirect 301 / http://domain.com/

301 redirect from domain to domain:
RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain2.com/$1 [R=301,L]

301 redirect to another page or site:
Redirect 301 /page1.html http://domain.ru/page2.html rel="nofollow"

Redirect to main domain:
RewriteCond %{HTTP_HOST} ^subdomen.site.com$ [NC]
RewriteRule ^(.*)$ http://site.com%{REQUEST_URI} [R=301,NC,L,QSA]

Redirect from www to non-www:
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

Redirecting from non-www to www:
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

Redirect from http to https:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [R,L]

Redirect from https to http:
RewriteCond %{HTTPS}=on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

Redirect from index.php
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule (.*) http://%{HTTP_HOST} [R=301,L][
 
Top