Melvin Kiran
Melvin Kiran

Reputation: 35

Using HTTP Host in filesmatch in htaccess

I am trying to match my sitemap based on host and it doesn't seem to be working. Can you help me figure this out.

My sitemap is sitemap-localhost.xml since i am running on my local

I have tried

<FilesMatch (sitemap-%{HTTP:Host}.xml)>
Order Deny,Allow
Allow from all
</FilesMatch>

<FilesMatch "sitemap-%{HTTP:Host}.xml">
Order Deny,Allow
Allow from all
</FilesMatch>

<FilesMatch sitemap-%{HTTP:Host}.xml>
Order Deny,Allow
Allow from all
</FilesMatch>

But nothing seems to work. The problem is I have two domains pointing to the same folder in the server and the two domains have two sitemaps.

Upvotes: 1

Views: 318

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

FilesMatch directive is designed to match against files only. You can not check HTTP_HOST header or URL path using this directive, only filename with its extension is allowed in the pattern.

If you want deny access to an xml file of a specific Host ,for example To deny access to thishost.com/sitemap.xml you can use mod-rewrite` .

RewriteEngine on

RewriteCond %{HTTP_HOST} ^thishost\.com$
RewriteRule ^/?sitemap\.xml$ - [R=403,L]

This will return a 403 error to clients if they visit thishost.com/sitemap.xml .

The leading slash ( /? ) in the pattern above is optional so that the Rule can work in both contexts htaccess and server.config .

Upvotes: 1

Related Questions