htaccess 301 redirect code example

Example 1: redirect 301 htaccess

redirect 301 /url_antigua.html http://www.dominio-nuevo.com/url-nueva/

Example 2: redirect htaccess non www to www

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Example 3: 301 redirect htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://domain2.com/$1 [L,R=301,NC]

Example 4: 301 redirect

301, "Moved Permanently"—recommended for SEO
302, "Found" or "Moved Temporarily"
Meta Refresh

Example 5: 301 redirect http to https

#For apache .htaccess
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Example 6: redirect htaccess 301

Redirect 301 /pagename.php http://www.domain.com/pagename.html

Tags:

Html Example