How to redirect all users from one website to another using .htaccess

Rumman Ansari   2023-12-05   Developer   web development > How to redirect all users from one website to another using .htaccess   45 Share

To redirect all users from one website to another using .htaccess, you can use the Redirect directive. Here's a simple example:


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^ https://www.newwebsite.com/ [R=301,L]
</IfModule>

This rule assumes that you have the mod_rewrite module enabled on your Apache server. If it's not enabled, you can usually enable it in your server configuration.

This rule will redirect all requests to https://www.oldwebsite.com to https://www.newwebsite.com/ with a 301 (permanent) redirect. The L flag indicates that this is the last rule to be processed.

Make sure to replace https://www.newwebsite.com/ with the actual URL of the website you want to redirect to.

Please note that modifying the .htaccess file can have serious consequences if not done correctly, so it's always a good idea to create a backup before making changes. Additionally, if you don't have access to the server configuration, make sure that your hosting provider allows the use of .htaccess files for such configurations.