how to redirect all pages to other domain using htaccess file

how to redirect all pages to other domain using htaccess file

There is only one line code, that you have to put on .htaccess to redirect all the pages of your website or web application to new website, domain, or application.

Here, this one redirects everything after the domain name on the URL to the exact same copy on the new domain URL:

Here 10 methods are given. You can select which method is working for you.


Method 1. Add this code in your .htaccess file.

RewriteEngine on 

RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]


Method 2. Add this code in your .htaccess file.

Options +FollowSymLinks

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^OLDDOMAIN\.com$ [NC]

RewriteRule ^(.*)$ http://NEWDOMAIN.com [R=301,L]


Method 3. 

RewriteEngine On

RewriteRule ^(.*)$ http://newdomain.com/ [R=301]


Method 4. 

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^YOURDOMAIN\.example$ [NC]

RewriteRule ^(.*)$ https://YOURDOMAIN.example/$1 [R=301,L]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

</IfModule>


Method 5. 

<IfModule mod_rewrite.c>

  RewriteEngine On

  RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]

  RewriteCond %{HTTP_HOST} ^www.olddomain.com$

  RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]

</IfModule>


Method 6.

Redirect 301 /Old-Location/ http://subdomain.yourdomain.com


Method 7. 

RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$

RewriteRule ^ http://newdomain.com%{REQUEST_URI} [NE,L,R] 


Method 8.

Options +FollowSymLinks

RewriteEngine On

RewriteBase /

RewriteRule .* https://www.newdomain.com/? [R=301,L]


Method 9.

RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]

RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$

RewriteRule ^(.*)$ "https\:\/\/newdomain\.com\/" [R=301,L]


Method 10.

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

</IfModule>

Comments

  1. Well explained. The step 1. is worked for me. thanks.

    ReplyDelete

Post a Comment