The .htaccess file is a configuration file used by Apache web servers to control various aspects of website behavior. It allows you to modify server settings, enable/disable features, and perform URL rewriting, including domain redirection.
- Connect to your web server using FTP or a file manager.
- Locate the root directory of your domain. The root directory is named public_html, www, or the domain name itself.
- Look for the .htaccess file (if it doesn't exist, create a new file and name it ".htaccess").
- Create a backup of the existing .htaccess file. This allows you to revert back to the original file if needed.
- Open the .htaccess file and add the following lines of code:
RewriteEngine OnRewriteCond %{HTTP_HOST} ^yourdomain\.com [NC]RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]
Replace "yourdomain.com" with your current domain and "newdomain.com" with the destination domain. The above code redirects all requests from the old domain to the corresponding URL on the new domain.
- Save the .htaccess file and upload it to the root directory of your domain.
- Upload the edited or new .htaccess file to your server using FTP or the file manager.
- Test the redirect by entering the original domain in a web browser, and ensure the redirect is functioning correctly.
Working with the .htaccess file requires attention to detail, as misconfigurations can lead to website errors or disruptions.
