A .htaccess rule that will divert any page in another folder


1)If you want to redirect http://test.com/f1/  to  http://test.com/f2/.
 .htaccess file will be.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^f1.*$ http://test.com/f2/ [R=301,L]


2)If you want to redirect http://test.com/f1/test.html to http://test.com/f2/test.html.
 .htaccess file will be.

Options +FollowSymLinks
RewriteEngine On
RewriteRule RewriteRule ^f1/(.*)$ http://test.com/f2/$1 [R=301,L]

3) If you want to redirect http://test.com/ to http://www.test.com/.
 .htaccess file will be.


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^test.com [NC]
RewriteRule ^(.*)$ http://www.test.com/$1 [R=301,L]

4) If you want to redirect  http://test.com/ to https://test.com/.

 .htaccess file will be.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.test.com/$1 [R,L]