AddRedirectToWww() redirecting to wrong domain - azure

I'm using the AddRedirectToWww rule for the rewriter middleware and I keep getting redirected to the wrong domain.
For context, my website is hosted on azure app service which has a default domain of myapp.azurewebsites.net. I have a custom domain say myapp.com and www.myapp.com.
I setup the rule so traffic from myapp.com gets redirect to www.myapp.com. However, what is happening is upon hitting myapp.com I get a redirect towards www.myapp.azurewebsites.net.
Any reason for why this is so? Does this middleware require specific request headers to determine the right host?

From the scenario and configuration you described, it looks like you have not set CNAME and TXT record correctly. You need to configure this in your Domain Registrar/Provider.
You need to map a subdomain (for example, www.myapp.com) by using a CNAME record.
Map a root domain (for example, myapp.com) by using an A record.
Kindly refer this document for step-step process.

Related

Redirect www to non-www on Azure Dns Zone

I have created Azure DNS Zone to manage redirections which use domain from namecheap.
Let's assume that my website is www.johndoe.com and currently website working well for johndoe.com but when I call www.johndoe.com it doesn't work well.
I have CNAME record and in CNAME redirect to redirect but unfortunately it doesn't work.
When I have call www.johndoe.com response message is as following...
Our services aren't available right now
We're working to restore all services as soon as possible. Please check back soon.
Please take into account that DNS does not provide a redirect.
An additional A or CNAME record only provides your IP address to people that navigate to that specific URL. When www.johndoe.com and johndoe.com both resolve to your web server, this means each page on your site has two addresses. This is horrible for things like SEO.
For a true redirect (and a 301 is preferred for SEO), set something up in the service that's handling the traffic coming in.
For instance: if you have an App Service running ASP.NET, setup the redirect in web.config. If you have Front Door (or a CDN) in place, use the rules engine to create a redirect with the correct condition and action.
Here's an example redirect in an Azure Front Door Classic Resource (this one redirects the other way):

Custom Domain to Azure CDN Endpoint with and without www

I have created an Azure CDN, an endpoint and working fine.
Created a CNAME www.mydomain.com to myazurecdn.azureedge.net
Created another CNAME mydomain.com to www.mydomain.com
In Azure Endpoint, Custom Domain, I updated www.mydomain.com and it got propagated.
Now, when I navigate to www.mydomain.com, everything works fine but when I navigate to mydomain.com i get below response.
Our services aren't available right nowWe're working to
restore all services as soon as possible. Please check back soon.
Note: As Azure endpoint accepts multiple custom domain, I could add both www.mydomain.com and mydomain.com but it is not correct way, as I have many <a> tags with www.mydomain.com/link.
What to be done now to instruct system to use same route for mydomain.com and www.mydomain.com?
Is domain redirect from domain.com to www.mydomain.com only option?
Have a look at this,
A custom domain and its subdomain can be associated with only a single
endpoint at a time. However, you can use different subdomains from the
same custom domain for different Azure service endpoints by using
multiple CNAME records. You can also map a custom domain with
different subdomains to the same CDN endpoint.
You can use different subdomains in the same endpoint. Alternatively, I think you also could create two endpoints, one is for the root domain without www, the other is for a subdomain with www.
I would say, you can implement redirection in your server or CDN.
When someone tries to access example.com, you can do a 301 by sending http://www.example.com in the location header.

Add custom domain to Azure web app without validation

I am on a project that is re-platforming a site from a web server to an Azure PaaS web app, in addition the site will have all new content and in some cases new URLs. We have some redirects in place to handle the mapping of old URL's to new ones. I would like to test that these redirects work correctly on my new azure web app. Normally I would update my hosts file to point at the new server, add an IIS binding so the correct website picks it up and go from there. However I don't seem to be able to bind a new hostname ("custom domain") without verifying that I own the new host name. It will just be my internal DNS that I will be altering to re-route my requests. Does anyone know how to add a custom domain in the azure web apps without validating? This doesn't sound like a big ask to me.
Thanks
Will
You can't do it without any verification, but you can do it without pointing traffic away from your existing site to your new site.
To verify you own the domain without redirecting traffic to it yet, create a DNS record called a TXT record with your domain registrar.
the "TXT host" should be
awverify.mysubdomain.mydomain.com
or
awverify.mydomain.com
The "value" should be
myapp.azurewebsites.net
just replace "mysubdomain" and "mydomain" and "myapp" with your specific info.
After you do this, the verification should succeed and you can add the custom hostname.
Here is more info about this: https://learn.microsoft.com/en-us/azure/app-service/manage-custom-dns-migrate-domain
You can use either a CNAME record or an A record to map a custom DNS name to App Service.
We recommend that you use a CNAME for all custom DNS names except a root domain.
If you missed a step or made a typo somewhere earlier, you see a verification error at the bottom of the page.
If you will use A record, you can create a TXT record to map to the app's default hostname .azurewebsites.net. App Service uses this record only at configuration time, to verify that you own the custom domain. After your custom domain is validated and configured in App Service, you can delete this TXT record.
Reference: https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-custom-domain.

How do i connect my windows azure website with my domain name perfectly?

I did almost everything that have described in the azure documentation briefly.
My domain names that i need to be assigned with my azure website url idaa.azurewebsites.net are mostout.com and www.mostout.com.
When trying to enter my site using any of the links added here, the site loads and works perfectly as i need.
But the problem is with my url which is getting loaded in browser url field while giving mostout.com or www.mostout.com.
It comes with the azure website url every time. What do I do now to get it working?
Make sure to set the CNAME for your service: have the www. name point to the full azurewebsites.net address.
Note that you'll:
need to have a level of service that supports custom domains with Windows Azure Web Sites,
add the CNAME from your www. domain to the azurewebsites domain (same goes for having the naked domain name via an A record or similar)
add the verification names, awverify.www.yourdomain.com and awverify.yourdomain.com
use the Manage Domains function in the portal for the web site to customize that domain name,
Things should just work then.

Static hosting on Amazon S3 - DNS Configuration

I'm working on a little webapp (all client-side) I want to host it on Amazon S3. I've found several guides on this and have managed to create myself a bucket (with the same name as my domain), set it as a website and upload some content.
Where I'm struggling, and where all the documentation starts to get a bit vague, is how to properly configure my DNS.
All my registrar (123-reg) could suggest was web forwarding which gives me mydomain.com.s3.amazonaws.com
What do I have to configure, and where (ie. 123-reg / Amazon) can I get a clean URL?
Sounds like you've done most of the work already. For clarity I'll go over those steps again just to make sure you're set up properly:
Create an s3 bucket using your domain name as the bucket name (your bucket name should be www.example.com if you want your site to be example.com or www.example.com)
Upload your content to the s3 bucket. Choose a consistent name for your website index files (index.html usually). You can also upload a custom page for 404 Not Found errors. Call this 404.html. Give Read permissions to every file in your website so that the public can view it. Don't give any extra permissions to the bucket, just the files within.
Configure your bucket as a website. With the AWS console ( https://console.aws.amazon.com/s3/ ) you can select your bucket, click properties, then select the "Website" tab. Click enabled and set your index document to index.html and your error document to 404.html. You will also need to set your bucket with access permissions to allow access via the web (http://docs.amazonwebservices.com/AmazonS3/latest/dev/WebsiteAccessPermissionsReqd.html)
Take a note of the "Endpoint" URL in the website configuration tab. This is where your website lives. You can open the link in a new window and you should see your website just as it will look. Click around and make sure everything works as expected.
You MUST use the endpoint address in all steps below. The normal www.example.com.s3.amazonaws.com won't work - you need to use the regional version (http://www.example.com.s3-website-us-east-1.amazonaws.com/)
Now, we can set up the DNS to give you a clean, custom URL.
First, we will map www.example.com to your site.
Using your DNS provider's tools, (123-reg in your case) you need to create a CNAME record to map www.example.com to www.example.com.s3-website-us-east-1.amazonaws.com
The CNAME is the only thing you need if you just want www.example.com. Most people also want example.com to work so we need another step.
example.com is often referred to as a naked domain or the apex record of the domain. The reason it's a problem is that it can't be a CNAME. CNAMEs only work on subdomains like "www." This makes it more difficult to point at s3.
The usual approach is to use a service to automatically redirect any request going to example.com to point to www.example.com. This will then pick up your CNAME record and your site will be served from s3.
The automatic redirect is not possible with plain old DNS so you have to use another service. Some DNS providers offer this service along with their DNS (GoDaddy does, amazon route53 does not. Not sure about 123-reg)
If your DNS provider doesn't do it, there are a few free services. One that I've used is http://wwwizer.com/naked-domain-redirect - it doesn't require any registration or payment.
To use this type of service, you need to create a DNS "A" record for your naked domain. For the wwwizer.com service, you would need to create an A record to point example.com to 174.129.25.170. That's all!
So, with this setup, if a user types example.com into their browser, the following would happen:
DNS query: example.com -> 174.129.25.170 (wwwizer.com's service)
HTTP request to 174.129.25.170 for example.com
174.129.25.170 redirects example.com -> www.example.com
DNS query: www.example.com -> CNAME to www.example.com.s3-website-us-east-1.amazonaws.com
DNS query: www.example.com.s3-website-us-east-1.amazonaws.com -> points to Amazon S3
HTTP request for www.example.com is now served by Amazon S3
Enjoy!
Update 2019
As of today following DNS setting worked for me to get AWS S3 static website working :
I believe you must select all docs in your bucket, right click, and choose "Make Public". You must do this every time something changes in the bucket as well. I then usually right click on bucket, choose properties, choose permissions in right hand pane then add "Everyone as a "grantee" then give them only "list" permissions. The rest of your article is excellent. The part about the naked domain helped me resolve my issues. You can also have the naked domain redirected to the www domain within S3 under "Static Website Hosting" It's probably the easiest way.
Thanks again for all your help.
Tim
From the Advanced DNS screen on your 123-reg control panel
I started by clicking the "Reset DNS" button to the default 123-reg settings.
This gave me the following;
DNS EntryType PriorityTTLDestination/Target
* A 81.xx.xx.xx
# A 81.xx.xx.xx
# MX 10 xx0.123-reg.co.uk
# MX 20 xx1.123-reg.co.uk
I then added this entry
www CNAME www.example.com.s3-website-us-east-1.amazonaws.com
From their Manage DNS guide pdf it says the "# record" refers to "your domain in its purest form with no subdomain" ie the naked domain stackoverflow.com
But it doesn't mention what the "* record" is, I assumed it would be to catch all sub domains and thought it might over ride the CNAME record but this does not appear to be the case.

Resources