Answer the question
In order to leave comments, you need to log in
Redirect domain and subdomain via htaccess with one rule?
Good afternoon!
My htaccess on domain1 looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/file.php
RewriteRule ^(.*) https://domain2.com/ [L,R=301]
</IfModule>
Answer the question
In order to leave comments, you need to log in
If you are using .htaccess, then you most likely do not have access to the configuration of the web server (Apache or its replacement).
Also, most likely, your subdomain and domain have different "home folders" - for example, public_html\domain1.com
and public_html\subdomain.domain1.com
if you use cPanel. Accordingly, when accessing a subdomain, files are taken from its home directory, and one .htaccess is not enough - they are taken from different folders.
I see two options:
public_html
. However, this option needs to be tested separately. On different panels (and maybe on different servers), this works differently. Also, for the shared .htaccess to work, both root folders must not have their own .htaccess. Otherwise, the latter will apply.RewriteCond %{HTTP_HOST} ^(.*\.)?domain1\.ru$
RewriteRule ^.*$ https://domain2.ru/$0 [L,R=301]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question