I encountered a problem with my website domain. I deployed an ASP.NET Core 6 MVC project to an Azure App service, and it worked on the free Azure default domain domain.azurewebsite.net
.
I then added a custom domain purchased from another service provider, and configured my app to use this domain. It works well without any other problem.
But I found that both the last default domain and custom domain appear in Google search.
I tried to add 301 redirection and robots.txt
to redirect the request to last domain to custom domain, but the problem continues.
I want to show only the custom domain on search engine.
I checked the following question related to wordpress, but no help.
I hope someone help me with great heart. Any advice would be welcome.
Thanks in advance.
I checked QA from here and Azure Community for the solution, but still couldn't find.
We can implement this feature by following settings. Please replace the default domain name and use yours.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<rewrite>
<!--<rules>-->
<!-- Block access to Azure default domain names -->
<!--<rule name="Block Azure Default Domain" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^webapplication220240628111356\.azurewebsites\.net$" />
</conditions>
<action type="CustomResponse" statusCode="404" statusReason="Not Found" statusDescription="This page is not available." />
</rule>
</rules>-->
<outboundRules>
<!-- Add X-Robots-Tag header -->
<rule name="Noindex Azure Default Domain" preCondition="ResponseIsHtml">
<match serverVariable="RESPONSE_X_ROBOTS_TAG" pattern=".*" />
<conditions>
<!-- if request from default domain -->
<add input="{HTTP_HOST}" pattern="^webapplication220240628111356\.azurewebsites\.net$" />
</conditions>
<!-- set X-Robots-Tag -->
<action type="Rewrite" value="noindex, nofollow" />
</rule>
<!-- Precondition to check if response is HTML -->
<preConditions>
<preCondition name="ResponseIsHtml">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\WebApplication1.dll" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>