The .htaccess file is a configuration file used by Apache web servers to control the behavior of web requests. One of the most common uses of the .htaccess file is for URL redirection, which is the process of forwarding one URL to another. This can be useful for a number of reasons, such as redirecting broken links to working ones or changing the domain name of a website.
Here are the steps to use .htaccess redirection:
Create a new file called ".htaccess" in the root directory of your website. This is usually the same directory that contains your main index.html or index.php file.
Open the .htaccess file in a text editor and add the following code to redirect one URL to another:
Redirect 301 /old-url.html http://www.example.com/new-url.html
This code redirects the page "old-url.html" to "new-url.html" on the same domain using a 301 permanent redirect. Replace "old-url.html" and "new-url.html" with the actual URLs you want to redirect.
Save the .htaccess file and upload it to the root directory of your website using an FTP client or file manager.
Test the redirection by visiting the old URL in your web browser. You should be automatically redirected to the new URL.
Note: You can also use .htaccess redirection for more advanced scenarios, such as redirecting all URLs on a domain to a new domain or redirecting based on specific conditions. For example, you can use regular expressions to redirect all URLs containing a certain keyword to a new page or domain. However, it is important to be careful when using .htaccess redirection, as incorrect usage can lead to broken links and negatively impact your website's search engine rankings.
To redirect a domain and all of its URLs to another domain via .htaccess, you can use the following code:
RewriteEngine On RewriteCond %{HTTP_HOST} ^old-domain.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.old-domain.com [NC] RewriteRule ^(.*)$ https://new-domain.com/$1 [L,R=301,NC]
This code will redirect all traffic from the old domain and its URLs to the new domain while preserving the URL structure. Place this code in the .htaccess file of the old domain's root directory.
To redirect a domain and all of its URLs to another subdomain via .htaccess, you can use the following code:
RewriteEngine On RewriteCond %{HTTP_HOST} ^old-domain.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.old-domain.com [NC] RewriteRule ^(.*)$ https://sub.new-domain.com/$1 [L,R=301,NC]
This code will redirect all traffic from the old domain and its URLs to the subdomain of the new domain while preserving the URL structure. Place this code in the .htaccess file of the old domain's root directory.
To redirect your subdomain website to another subdomain with all URLs via .htaccess, you can use the following code:
RewriteEngine on RewriteCond %{HTTP_HOST} ^subdomain1\.example\.com$ RewriteRule ^(.*)$ http://subdomain2.example.com/$1 [R=301,L]
Replace "subdomain1.example.com" with the name of your current subdomain, and "subdomain2.example.com" with the name of the subdomain you want to redirect to. This code will redirect all URLs under the original subdomain to the corresponding URLs under the new subdomain.
Make sure to place this code at the top of your .htaccess file in the root directory of your subdomain1 website. This will ensure that the redirect is applied before any other rules in the file.
In my case, I need to redirect my subdomain https://app.arnlweb.com to a new subdomain https://lyrics.arnlweb.com . See here the working code.
RewriteEngine on RewriteCond %{HTTP_HOST} ^app\.arnlweb\.com$ RewriteRule ^(.*)$ https://lyrics.arnlweb.com/$1 [R=301,L]
Thank you visit my page, Good luck.