如何防止Google索引我的Azure App Service子域名xxx.azurewebsites.net?
Hey there, great question—this is a super common scenario when launching Azure App Service sites, so let's break down your two concerns clearly:
To steer Google toward your custom domain and away from the default Azure subdomain, follow these actionable, SEO-friendly steps:
Add Canonical URL Tags: Every page on your site should include a canonical link pointing to its corresponding xxx.com URL. For example, on
https://xxx.azurewebsites.net/contact, insert this in the<head>section:<link rel="canonical" href="https://xxx.com/contact">This explicitly tells search engines that the xxx.com version is the authoritative, preferred page.
Set Up Permanent 301 Redirects: Configure your Azure App Service to automatically send all traffic from
xxx.azurewebsites.nettoxxx.com. Here's how to do it in the Azure Portal:- Open your App Service resource.
- Go to Settings > Custom domains.
- Under Redirect all traffic to the primary domain, select
xxx.comas your primary custom domain and enable the redirect.
301 redirects signal to search engines that the Azure subdomain has permanently moved to xxx.com, so they'll transfer any existing index weight and stop indexing the old domain.
Configure Google Search Console:
- Submit both
xxx.comandxxx.azurewebsites.netas separate properties in Google Search Console. - Verify ownership for both (you can use Azure DNS verification for a smooth setup).
- Set
xxx.comas your preferred domain in the settings for both properties. - Once the 301 redirect is fully active, use the Remove URLs tool in Search Console to request Google deindex the
xxx.azurewebsites.netpages.
- Submit both
Block Crawlers on the Azure Subdomain: Create a
robots.txtfile exclusive to thexxx.azurewebsites.netdomain (ensure this doesn't apply to xxx.com) with the following content:User-agent: * Disallow: /This tells all search crawlers to avoid indexing any pages on the Azure subdomain, adding an extra layer of protection.
Yes, by default, Azure App Service keeps the xxx.azurewebsites.net domain publicly accessible even after you add your custom xxx.com domain. That's why the 301 redirect step is so important—it ensures all users land on your branded domain instead of the Azure subdomain, and it reinforces your SEO priorities.
If you want to block direct access to the Azure subdomain entirely (instead of redirecting), you have two options:
- Use Azure App Service's IP restrictions feature to allow only your internal/maintenance IPs to access
xxx.azurewebsites.net - Add a rule in your app's code (e.g., in ASP.NET, Node.js, Python, etc.) to check the request host and return a 403 Forbidden response if it's
xxx.azurewebsites.net
内容的提问来源于stack exchange,提问作者Ashkan S

