K
K
kamsar2020-03-21 19:12:28
Search Engine Optimization
kamsar, 2020-03-21 19:12:28

How to make a different redirect for subdomains and non-subdomains on .htaccess?

The essence of the site works on the main domain and regional subdomains. The site has different sitemaps, those that are available on the main domain should not be available on the other.

That is, the condition is as follows:
If a person visits the site site.ru/sitemap-blablabla... do nothing.
If a person went to the site site.ru/region-sitemap-bl... - give a 404 error.
If a person went to the site REGION.site.ru/region-sit... - do nothing.
If a person went to the site REGION.site.ru/sitemap-bl... - give a 404 error.

i.e. there are many sitemaps, but the difference for regional ones starts with region-sitemap for the main site they start with sitemap.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2020-03-21
@shambler81

RewriteCond %{HTTP_HOST} ^site\.ru$
# if this is the main domain
RewriteRule ^region\-sitemap\.xml$ ? [L,R=301]
RewriteRule ^.+$ https://sitemap\-.+/? [L,R=404]
# Main domain sitemap
404
RewriteCond %{HTTP_HOST} !^www\.site\.ru$
# if this is not a domain with www
RewriteCond %{HTTP_HOST} ^.+\.site\.ru$
# if this is a third level domain
RewriteRule ^.+$ https://sitemap\-.+/? [L,R=404]
# main domain sitemap 404

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question