Logo

How to Htaccess File Using Redirect

Posted Sunday, September 19, 2021 ( 1 month ago)
  1. Creating and Uploading a .htaccess File

  2. Redirect www to non-www in .htaccess

  3. How to htaccess Redirect Whole Site

  4. How to htaccess Redirect Whole Site

  5. How to htaccess Redirect HTTP to HTTPS

  6. How to htaccess Redirect HTTPS to HTTP

  7. htaccess Redirect to Subfolder Without Changing URL

  8. htaccess Redirect Directory

1. Creating and Uploading a .htaccess File

  • Click the New File button in the upper menu.
  • Enter .htaccess as the file name, insert the code below and press Create to save your changes.

2. Remove the Need for www in Your URL

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

3. Redirect non-www to www in .htaccess

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

4.1 How to htaccess Redirect Whole Site / htaccess Redirect Domain

how to htaccess redirect a domain

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^OLDDOMAIN.com$ [NC]
RewriteRule ^(.*)$ http://NEWDOMAIN.com [R=301,L]
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]

5. How to htaccess Redirect HTTP to HTTPS

Add this code at the end of your .htaccess file

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

6. How to htaccess Redirect HTTPS to HTTP

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

7. htaccess Redirect to Subfolder Without Changing URL

Redirect 301 /path/to-old-url    http://www.expertsnote.com/path/to-new-url

7.2 contents of a whole directory to another use

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

7.3 Whole Directory to the Webserving root

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

7.4 Subdirectory to Aother Domain but in the same Subdirectory

 Redirect 301 /subdirectory http://www.anotherdomain.com/subdirectory

8. htaccess Redirect Directory

RewriteEngine On
RewriteRule ^/Old/ /new/[R=301,L]