-1

I want to redirect my subdomain to main domain, except the root.

I did this:

RewriteCond %{HTTP_HOST} ^sub.main.com$ [NC]
RewriteRule ^(.*)$ https://www.main.com/$1 [R=301,L]

So this code redirects all URLs from sub to main, but I want the root of

sub.main.com

to take place in a URL like this

www.main.com/sub-category

I tried many things. One was:

First: sub.main.com to sub.main.com/index.php After: sub.main.com/index.php to www.main.com/sub-category

I also found something similar but i am stuck

Redirect site with .htaccess but exclude one folder

And many more ...

I couldn't get it done.

Could somebody please help?

Thanks in advance.

1 Answers1

0

Try:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub.main.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ https://www.main.com/sub-category [R=301,L]

RewriteCond %{HTTP_HOST} ^sub.main.com$ [NC]
RewriteRule ^(.*)$ https://www.main.com/$1 [R=301,L]

This will redirect:

  1. sub.main.com/xyz to https://www.main.com/xyz
  2. sub.main.com/ to https://www.main.com/sub-category
Example person
  • 3,198
  • 3
  • 18
  • 45