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
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.
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:
sub.main.com/xyz
to https://www.main.com/xyz
sub.main.com/
to https://www.main.com/sub-category
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.