Redirect using .htaccess 301
One of the better and easier ways to redirect is using .htaccess 301 redirect. What is “.htaccess”?
“.htaccess is a configuration file for use on web servers running the Apache Web Server software. When a .htaccess file is placed in a directory which is in turn ‘loaded via the Apache Web Server’, then the .htaccess file is detected and executed by the Apache Web Server software. These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer. These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions such as content password protection or image hot link prevention.” htaccess-guide.com
Always be sure to upload .htaccess files in ascii mode.
To redirect a single page:
To redirect an entire site:
To redirect /index.php to yourdomain.com/
RewriteEngine on
# index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3, 9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
To redirect /index.html to yourdomain.com/
RewriteEngine on
# index.html to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3, 9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
To redirect non-www to www — It’s a good idea not to confuse search engines. More information on “canonical url errors“.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
To redirect www to non www — the opposite of the above.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]


