I have created a website on Azure, and linked it with custom domain name(CNET).
Now, when I look at domains on website configuration on Azure panel I see both www.mywebsite.com , and default mywebsite.azurewebsites.net. Both of these domains work fine and I can access website using any of these.
How can I remove mywebsite.azurewebsites.net domain? Does having both of these domains affect SEO?
EDIT*
Thanks for answers, I am trying to enable a 301 redirect, but it is not working. I have added this to web.config file ("example" being my actual site name)
<system.webServer>
<rewrite>
<rules>
<rule name="SEOAzureRewrite" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.azurewebsites.net$" />
</conditions>
<action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
I run the website but nothing happens. I can still access the mysite.azurewebsites.net address.
there is no problem in having both domains pointing to your website.
for SEO, you must do 301 redirect from mywebsite.azurewebsites.net to www.mywebsite.com.
It has to be 301 redirect. As this will tell the search engines to always index www.mywebsite.com
Since I couldn't set up the url rewrite in web.config, I created global filter to check for azure url and display error if so. Here is the filter, and I added a new view in my error pages for this purpose that just says "Page doesn't exist" to avoid indexing by search engines. Think this will solve possible duplicate indexing issues.
public override void OnResultExecuting(ResultExecutingContext context)
{
if (context.RequestContext.HttpContext.Request.Url != null)
{
string path = context.RequestContext.HttpContext.Request.Url.AbsoluteUri;
if (path.ToLower().Contains("mywebsite.azurewebsites") && !path.ToLower().Contains("error/oldazuresubdomainredirect650"))
{
throw new HttpException(650, "Azure legacy");
}
}
}
You can create a url rewrite rule to do exactly that
You just need to add a redirect rule to your site’s web.config file. You can do that by adding the following rewrite rule to the web.config file in your wwwroot folder. If you don’t have a web.config file, then you can create one and just paste the text below into it, just change the host names to match your site’s host names:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^yoursite\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="http://www.yoursite.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
The above is all you need to do to get it to work. If you'd like to better understand what exactly that code does and why it works, there's a detailed writeup at https://zainrizvi.io/blog/block-default-azure-websites-domain/
Related
I run a Sitecore multi site environment (c#/MVC). The same IIS website, same folder, same code is used for multiple websites. For example www.chalk.com and www.cheese.com, very different looking sites but both use the same IIS website (host headers), same folder, same web config, same database backend.
All is good except the error page. In the web.Config I have the usual setting:
<customErrors defaultRedirect="/error.html" mode="RemoteOnly" />
I need something like
<customErrors mode="RemoteOnly">
<error host="chalk.com" defaultRedirect="/chalkerror.html">
<error host="cheese.com" defaultRedirect="/cheeseerror.html">
</customErrors>
Is something like this possible?
In case anyone finds this question...
for me, I found the answer in Rewrite Rules.
NOTE: You need the URL Rewrite IIS Extention installed. (Download Here)
I added to the Web.Config
<system.webServer>
<rewrite>
<rules configSource="folder\filename.config" />
</rewrite>
</system.webServer>
And then a config file (filename.config)
<?xml version='1.0' encoding='utf-8'?>
<rules>
<rule name="Error-Chalk" patternSyntax="Wildcard" stopProcessing="true">
<match url="error.html" />
<action type="Rewrite" url="chalkerror.html" />
<conditions>
<add input="{HTTP_HOST}" pattern="*chalk*" />
</conditions>
</rule>
<rule name="Error-Cheese" patternSyntax="Wildcard" stopProcessing="true">
<match url="error.html" />
<action type="Rewrite" url="cheeseerror.html" />
<conditions>
<add input="{HTTP_HOST}" pattern="*cheese*" />
</conditions>
</rule>
<rules>
This line <add input="{HTTP_HOST}" pattern="*cheese*" /> makes the match on the domain name, so www.cheese.com or image.cheese.com will match. <match url="error.html" /> matches the page being asked for. <action type="Rewrite" url="cheeseerror.html" /> is the page IIS will serve. I can now have the different error page for the different site.
Apparently, this isn't achievable. customErrors settings work to redirect to error pages targeted for specific HTTP error codes.
However, As you mentioned, its an MVC application, you can create a Custom Error Handler MVC filter which checks for host\domain and based on that redirects to the required ErrorView.
Also, here are 6 great methods described to achieve expected behavior MVC Exception Handling
Is it possible to remove a subdomain (or basically treat it like www) from the URL?
Example:
subdomain.domain.com/specific/link/forsubdomain -> domain.com/specific/link/forsubdomain
and not have it point to the primary domain and return a 404 error,
example:
domain.com/specific/link/forsubdomain -> return a 404 because it only exists in the subdomain.
If it's possible to do something in Haproxy as well Or disguising URLs in ASP.net MVC Route table modifications im open to it.
Not just IIS configuration.
Just wanted to know if it's possible to change the URL as i described and still have it point to the subdomain site.
If I understand your question correctly you are refering to canonical URLs.
Within IIS you can use URL Rewrite, which is a module you can install manually or via the Web Platform Installer (if it's not already installed).
This allows you to create a url rewrite rule which you can configure per site, something along the lines of;
<rule name=”Redirect URL to WWW version”
stopProcessing=”true”>
<match url=”.*” />
<conditions>
<add input=”{HTTP_HOST}” pattern=”^example.com$” />
</conditions>
<action type=”Redirect” url=”http://www.example.com/{R:0}”
redirectType=”Permanent” />
</rule>
You can add the rules manually to the site's web.config file or use a GUI within the IIS site manager tool.
There's a lot of reference and a number of tutorials available from Microsoft and numerous bloggers.
An example of a complete web.config just doing this type of redirect.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WWW Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^contoso.com$" />
</conditions>
<action type="Redirect" url="http://www.contoso.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Is there a setting to force the language in the URL? Like, if I browse to http://www.site.com, I should be redirected to http://www.site.com/en, as it is now I can see the start page without the language prefix.
The LinkManager is configured to always put in the prefix so all the links look fine at least.
Another way to use is our SEO Friendly URL Module.
This module implements a custom LinkProvider that provides SEO Friendly URL's and forces items to be accessed through their friendly URL.
So if an item is accessed without the language code in the URL (e.g. /my-item) the module will 301 redirect to the URL with language code (e.g. /en/my-item).
That is, if you have configured it to force friendly URL's (forceFriendlyUrl="true") and set languageEmbedding="always".
We use that module on our corporate website, so take a look at that to see it in action.
You can use ISS URL Rewrite to redirect / to /en
Install that module on the IIS, and setup a rule.
It can be done from the IIS gui or from web.config
I am using this rule to do the same.
Insert the following configuration in the system.webServer section in web.config
<system.webServer>
<rewrite>
<rule name="redirert / to en" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAny">
<add input="{PATH_INFO}" pattern="^/$" />
</conditions>
<action type="Redirect" url="/en/" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
It will redirect every request hitten "/" to "/en"
First of all, I just spent a few hours on Stackoverflow reading similar questions but no answer seems to work for me.
I have an MVC4 application which has an SEO issue : the non-www is not redirected to www. I have installed the Rewrite module on the server (IIS7.5) and on my local environment (VS2010).
I tried many ways but none seems to work...
Ideally, I would prefer to have the rewrite rule in my MVC4 solution and avoid doing server side configuration as it is more convenient when deploying to new servers.
I tried to put the following code block in my web.config :
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
<!-- code added for SEO non-www to www redirect -->
<rewrite>
<rules>
<rule name="Remove WWW prefix" >
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}"
redirectType="Permanent" />
</rule>
</rules>
</rewrite>
<!-- SEO code -->
</system.webServer>
I then published the solution (with the right domain name) but nothing changes. When trying to access http://domain.com, I just get a 404 not found error.
I tried several code block for this part but it just never work. I also tried to configure this on the server, which didn't work as well. The best solution would be to have this rewrite in my web.config so the rules are applied whenever I publish to a new web server.
Does anyone sees something wrong with this ? My web.config is in my MVC4 application and published via the Publish menu we get when right-clicking the solution in VS2010.
Thank you very much in advance for your replies.
I also tried this block for the rule but it doesn't change anything..
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" redirectType="Permanent" />
</rule>
I want to make some redirects:
/Home => /en/us/Home
/ => en/us/
Where should I put these redirects and how should I redirect to avoid getting an infinite loop?
Instead en/us I want to extract the values that the users browser is submitting.
Thank you for your Help!
These things go into web.config. Look at this article. This is for IIS7, but I think II6 supports this as well.
In your case you would add something like this into web.config:
<system.webServer>
<rewrite>
<rules>
<rule name="rule1" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern="^en/us/?" negate="true" />
</conditions>
<action type="Redirect" url="/en/us/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
This will catch all your non /en/us URLs and redirect them to the URL that starts with /en/us/ and what ever was in the original URL.
Note that this does not have the ability to test for actual location of the user. For that you'd probably have to use some logic.