Htaccess Redirection


  • Redirect All Pages to to index.html

To redirect all your pages to index.html or index page you can use following script on your .htaccess. This will redirect all pages/url to index.html. To use index.php instead of index.html simply change index.html to index.php.


RewriteEngine on

RewriteCond %{REQUEST_URI} !^/index.html$

RewriteRule .*\.(php|html)$ / [L,R=302]


  • Redirect all url to another domain 

To redirect all URL to another domain you can use script below

eg. redirect to

Options +FollowSymLinks

RewriteEngine on

RewriteRule (.*) [R=301,L]


  • Redirect all Pages/URL to root/domain

When you need to redirect all your pages to index page you can use script below.

eg. redirect , httpd:// to

RewriteRule ^.+$ / [R=302,NC,L]

  • Redirects everything after the domain name on the url to the exact same copy on the new domain url:
RewriteEngine on 
RewriteRule ^(.*)$$1 [R=301,L] redirects to

  • Redirect non-WWW to WWW

When you keep your main URL as www but when you open URL it also show with www as well, then you can force redirect URL to use www from script below.

eg. to

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\. [NC]

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


  • Redirect All Pages/URL to Another 
RewriteEngine on

RewriteCond %{HTTP_HOST} ^[NC,OR]

RewriteCond %{HTTP_HOST} ^ [NC]

RewriteRule ^(.*)$$1 [L,R=301,NC]


  • Redirect to https://www

You setup SSL on website but the website still opens on non ssl URL (http) instead of https? Use following script  to force redirect to use https://www on your URL.

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]