CWP panel

How To redirect a main domain to a another subdomain using htaccess || C-panel



To redirect a main domain to another subdomain using .htaccess, you can use the following code:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*)$ [R=301,L]

In the code above, replace “example.com” with your main domain and “subdomain.example.com” with the subdomain you want to redirect to.

The code checks if the incoming request is for the main domain, either with or without the “www” prefix, using the RewriteCond statements. If the condition is true, the RewriteRule statement redirects the request to the corresponding subdomain.

The [R=301,L] at the end of the RewriteRule statement specifies that the redirect is a permanent (301) redirect and that it is the last rule to be applied.

Note that you will need to have mod_rewrite enabled in your Apache configuration for this to work.

[ad_2]

source

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button