Htaccess Redirect Generator

The Best Free SEO Tools

Htaccess Redirect Generator


1. Select redirect type





2. Enter your domain name


Do not include www. Domain name only - e.g. yourdomain.com

3. Get your code


4. Copy the code to your .htaccess file



About Htaccess Redirect Generator

Htaccess Redirect Generator, as the name suggests, is a very handy SEO Tool offered free of charge by Seoprimetools.com that helps webmasters to create line of codes that can be used to redirect a site from www to non-www or from non-www to www. 

Below are just some of the few examples you can use to fix your site redirect issues, improving at the same time, your online presence.

Say you need help with 301 redirect from subdomain to root domain:

To redirect requests for "subdomain.example.com/uri to example.com/uri" you can use:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.example.com$
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

To redirect requests for "subdomain.example.com/uri to example.com/"

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.example.com$
RewriteRule ^(.*)$ http://example.com/ [R=301,L]

To redirect requests for "olddomain.com/uri to newdomain.com/"

RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/ [L,R=301,NC]

To redirect requests for "olddomain.com/uri to newdomain.com/uri"

RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301,NC]

To redirect from old domain with sub-directory to new domain w/o sub-directory including full path and query string

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subdirname/(.*)$
RewriteRule ^(.*) http://www.newdomain.com/%1 [R=302,NC] 

How to force SSL with .htaccess

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]


Advertise With Us!
Advertisement!...

Most Popular Free SEO Tools