Tag Archives: htaccess

How to redirect your old domain to your new domain using .htaccess

if you want to make a test you should probably use 302 (temporary) n stead of 301, once you are comfortable that this is what you want make it permanent using 301

The  .htaccess instructions to add in the OLD site are the following:

Option 1:

<IfModule mod_rewrite.c>
  RewriteEngine On
  #this will redirect all your links to the root of your new domain 
  RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.olddomain.com$
  RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>

Example:

http://francesco-lelli.users.sourceforge.net/technicality/2014/07/solve-media-plug-in-in-wordpress-and-php-editing/

Will redirect to:

 http://technicality.host-for.me

If you tried you will noticed that it does not work! The reason is that i chose Option 2:

<IfModule mod_rewrite.c>
  RewriteEngine On
  #this will redirect all your links to the same links in your new domain

Redirect 301 / http://technicality.host-for.me

Example:

http://francesco-lelli.users.sourceforge.net/technicality/2014/07/solve-media-plug-in-in-wordpress-and-php-editing/

will redirect to:

http://technicality.host-for.me/2014/07/solve-media-plug-in-in-wordpress-and-php-editing/

 

 

htaccess redirect www to no-www and remove index.html

This is a useful generic rewrite instruction to insert into the .htaccess file:

Rewrite

RewriteEngine On

#http://www.*/blabla.xyz —-> http://*/blabla.xyz

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

#http://*/xyz/index.html —-> http://*/xyz/

  1. RewriteRule ^index\.html$ / [R=301,L]
  2. RewriteRule ^(.*)/index\.html$ /$1/ [R=301,L]

Other useful rewrite rules for rewriting the home to a given file or directory:

  1. RewriteRule ^$ /myfile.html [R=302,L]
  2. RewriteRule ^$ /mydir/ [R=302,L]