ASP.Net MVC Redirect to WWW domain version - asp.net-mvc-routing

For SEO purposes, I want to do a 301 redirect when anyone hits my domain name without the www. prefix. So, redirect from http://mydomain.com/{page} to http://www.mydomain.com/{page}.
Can I accomplish this with MVC routes? Or should I put some sort of global action filter on every controller?

No doubt you could, but the only reason to do so would be to demonstrate that you could.
In IIS, set up a website for the non www. domain.
Set it to do the redirect, not "to the exact URI" checked, because you want it to match "/{page}" to "/{page}", and also unless you plan to change this policy in the near future "permanent redirect" because unless you plan to change this policy in the near future, then for SEO purposes you do not want to 302, you want to 301.

Related

Redirect Domain to Subdomain using Cloudflare

I'm using a marketing automation platform to build landing pages and those landing pages URLS are automatically published with a subdomain structure, like:
https://subdomain.example.com/mylandingpage
I want to redirect all www and non www visits to the main domain to this landing page that I created, in other words I wish the https://example.com and https://www.example.comto be redirected to https://subdomain.example.com/mylandingpage
Since I'm only using this platform and did not subscribe to any hosting, I'm trying to use Cloudflare to make all this redirects.
I saw a tutorial and this guy said that A entries in my DNS shouldn't be blank and recommended setting them to a reserved IP address, so I set both A entries to 192.0.2.0.
Ok, then I went to page rules and set a 301 redirect to *example.com to be redirected to https://subdomain.example.com/mylandingpage
I can see that when I visit my main domain it's redirected to the subdomain correctly, but the page doesn't load, and I get a too many redirections error. I believe that I made something wrong and it's redirecting everything to the subdomain, even the subdomain is redirecting to itself, even having a page path /mylandingpage after the hostname.
Did I make myself clear? Is there any other way to do what I want?
In Cloudflare page rules instead of *.example.com, please use exact domain match.
URL path we can use wildcard.
www.example.com/* - https://subdomain.example.com/mylandingpage
example.com/* - https://subdomain.example.com/mylandingpage

ColdFusion route redirects

Is there a way using ColdFusion to have a one page that can route url redirects? I have a bunch of one off page redirects and it is really weighting down my Git commands.
So Like:
abc/index
test/index
redirect/index
etc...
So I'm trying to figure out a way to move these all to one app that can route them to the correct redirect. Doing this on the server is not an option for me as our server admin has a lockdown on access.
the best is to have URL rewrites at the server level.
However, you can you use onRequestStart function in your Application.cfc and match the page being called and redirect accordingly.
Basically, have some logic added in the onRequestStart according to your needs.

New website on https, do I need to set up redirect?

We have an e-commerce website with in 4 languages running on ourbrand.com, ourbrand.de, ourbrand.fr etc. Currently 3 of those are running on http and the last one we are just ready to launch will be on https. I am trying to figure out if and how I need to set up htaccess redirect.
There is no history of running this new website on http (so no need to redirect existing http traffic), but I am sure that some people will type ourbrand.it or www.ourbrand.it directly to their browser's address bar. As far as I know, browser will default it to http://ourbrand.it right? So do I need to set up redirect to https? Which one? 301? Thank you.
Yes, because as you said, if your visitors type ourbrand.it the browser will default to http://ourbrand.it
The best thing to do is a 301 (permamant) redirect.
If you want to improve security and avoid that first redirect, your should look into HSTS and HSTS preload.

MVC Page routing replaces part of subdomain when subdomain text is also part of the route

I've got a strange problem with routing MVC paths to aspx pages. It all works find except for some rare scenario's. Actually not that rare as it's happened twice this month.
So We've got old aspx pages but we need to have friendlier URL's. That's the background, can't avoid it for reasons I won't go into.
So I have a page ~/MySubFolder/Plans.aspx
We need the URL to be ~/Things/Plans
so I have a page route in route config
routes.MapPageRoute("Tickets", "Things/Plans", "~/MySubFolder/Plans.aspx");
This all works fine in most circumstances.
The app is SaaS product and we determine the tenant in context based on the url they use. So each tenant gets a subdomain on our app like http://clienta.ourapp.com
So this is the problem.
We had a client sign up and they picked their subdomain to be http://plans.ourapp.com
The client does not have any problems except when they try to access our path ~/Things/Plans. when they do that we get an error. It's one of our own exceptions and it happens because on every request we determine who the tenant is by looking at the subdomain.
for some reason when we examine the domain name routing has stripped out the plans part of the sub domain name and is http:// .ourapp.com instead of http://plans.ourapp.com.
So this is obviously caused by the fact that the word plans is the subdomain and plans is also the end of the route Things/Plans
We need to somehow avoid this happening, maybe the route is not setup properly or maybe it's just a bug but would be great to figure out exactly why this is happening so we can fix it.
Thanks
So turns out this had nothing to do with routing the URLs. Somewhere else in code where we try to evaluate the current tenants URL we were for some reason replacing part of the URL based on another part of the URL which was the problem in some scenarios. No wonder no-one had an answer for this

Will re-direction from home page affect search engine crawling?

There is a new domain, let's say va.in.
Content is being prepared for the sub-domain a.va.in
The idea is that va.in/index could contain pointers to various sections sometime in future (e.g. b.va.in, c.va.in etc.). As of now, it does not make sense to have such a page as there is just one section i.e. a.va.in
If I decide to re-direct va.in to a.va.in for now, will the search engines follow the re-direct and index the site?
Is DNS the best place to do the re-direction?
Using "301 Moved Permanently" search engine will only index sub-domain a.va.in.
If that's ok, you can do this using web server's config.
For example in Apache:
<VirtualHost va.in www.va.in>
Redirect permanent / http://a.va.in/
</VirtualHost>
You can't really use DNS to do redirect, because in DNS you cannot assign CNAME to #.
See: Is Root domain CNAME to other domain allowed by DNS RFC?
There is question related to yours: 301 Redirect vs DNS change: Is it ever safe to kill a 301 redirect and update the DNS for a subdomain?
Yes, the search engines follow redirects, if you redirect with a HTTP header
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '.$location);
I don't know about DNS redirect, but I'd rather not use it..
You can read more about how to do a HTTP redirect here.
You can redirect in two ways.
Programaticlally as evilpenguin said
Using the webserver (Example iis)
But there is one thing common in both these options. The redirect must be permanent redirect if you want to inform search engines that va.in is permanently moved to a.va.in
If you dont specity permanent redirects, still crawlers will go to a.va.in but in this case they wont be notified that it is a permanet redirect.
If some one has bookmarked va.in and in the first case (permanent redirection) bookmarks will get updated. But in the second case book marks wont be updated.
Hope this helps.