MVC Page routing replaces part of subdomain when subdomain text is also part of the route - asp.net-mvc-routing

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

Related

Redirect with cname to subdomain while retaining cname web address

i have this problem where i have a subdomain sub.host.com and a new domain www.new.com. I want to redirect www.new.com to sub.host.com without showing the browser that the url had changed. The content is in sub.host.com but i want that even after the page has fully loaded, it is still showing www.new.com
This means also that when i go to sub.host.com/function, it should also appear as www.new.com/function
The reason is the actual subdomain looks ugly and contains numerics. Is this possible to do? Ive tried searching but all that comes up are only about how to go about creating cname records and none about keeping it intact after redirecting. Thanks
A (reverse proxy) server like Nginx, which is very light-weight, features the url-rewrite rules that you need. IIS7 has also a good url-rewrite engine.

How to prevent Google from indexing redirect URL I do not own

A domainname that I do not own, is redirecting to my domain. I donĀ“t know who owns it and why it is redirecting to my domain.
This domain however is showing up in Googles search results. When doing a whois it also returns this message:
"Domain:http://[baddomain].com webserver returns 307 Temporary Redirect"
Since I do not own this domain I cannot set a 301 redirect, or disable it. When clicking the baddomain in Google it shows the content of my website but the baddomain.com stays visible in the URL bar.
My question is: How can I stop Google from indexing and showing this bad domain in the search results and only show my website instead?
Thanks.
Some thoughts:
You cannot directly stop Google from indexing other sites, but what you could do is add the cannonical tag to your pages so Google can see that the original content is located on your domain and not "bad domain".
For example check out : https://support.google.com/webmasters/answer/139394?hl=en
Other actions can be taken SEO wise if the 'baddomain' is outscoring you in the search rankings, because then it sounds like your site could use some optimizing.
The better your site and domain rank in the SERPs, the less likely it is that people will see the scraped content and 'baddomain'.
You could however also look at the referrer for the request and if it is 'bad domain' you should be able to do a redirect to your own domain, change content etc, because the code is being run from your own server.
But that might be more trouble than it's worth as you'd need to investigate how the 'baddomain' is doing things and code accordingly. (properly iframe or similar from what you describe, but that can still be circumvented using scripts).
Depending on what country you and 'baddomain' are located in, there are also legal actions. So called DMCA complaints. This however can also be quite a task, and well - it's often not worth it because a new domain will just pop up.

Google analytics: cross domain tracking + 301 redirect

I'm right now working on multiple websites from the same company each one connected to the others with a list of links on the top header.
The visits tracking is done with Google analytics and everything seems to be working fine. Too bad that they now seem to be unhappy with all the utm* parameters which get attached at the bottom of the url to obtain cross domain tracking.
For me the best solution seems to be this:
each url which links to another one of the sites is like 'www.somename.com/en' where 'en' is the desired language.
After clicking the new page opens with an url like 'www.somename.com/en?_utma=xxxxxxxx&_utmb=...'
If i remove from the links the language changing the href to 'www.somename.com' when the page loads,
the site makes a 301 redirect from 'www.somename.com/?_utma=xxxxxxxx&_utmb=...' to 'www.somename.com/en' where 'en' is the standard language, obtaining in this way exactly what the site owner desires.
Since i don't have access to the G anlaytics account i would like to ask if this might be the right solution or if we may be losing the cross domain tracking.
The cookie __utmz seems to contain the right referrer but I'm not sure if this can be considered enough to check if it is working.
But then i checked the other parameters here http://helpful.knobs-dials.com/index.php/Utma,_utmb,_utmz_cookies and it seems to me that all the other values on the cookies that we get after getting on the new domain don't have to be in any way related to the ones on the previous page (the site with the links).
What else should i check to be sure that everything is still working fine?
Thanks,
You will lose cross domain tracking (that is, even if you might salvage the traffic source the visitor session will be interrupted when changing the domain). One of the parameters added by the linker functions is a hash value (utmk) calculated from the various utm.. parameters. If the hash is missing or does not match the parameters cross domain tracking will be broken. You need to transfer the parameters to a javascript enabled page on the other domain so that the ga cookie can be updated - after that you can do 301 redirects at will.
If you want to avoid utm parameters you can
switch to universal analytics - requires a single parameter to be send; however you can't switch an GA acount to universal analytics, you would have to start from scratch (UPDATE: this is no longer true, you can and indeed should update existing properties)
try to get into the beta for the universal measurement protocol (which would even allow for javascript-less tracking - however you'd still need to send a single id from domain to domain)
So there is no real good solution for you. It is a lot better IMO to have some strange parameters in the url than to do a reload/redirect just to get rid of them.

Adding more than 1000 301 redirects in drupal site

I am using drupal 6.
I worked on the site revamp for one of our clients and we needed to redirect the old site urls to relevant new site urls so that we do not loose the traffic. I have used path redirect module for same and added some of the urls.
The issue is we have more than 1000 urls to be added and there is no specific pattern (as old site was in asp.) so it would be 1 to 1 mapping for redirect. Adding it in url alias table via path redirect module is something which is hitting the site performance and again it is a manual process.
Is there any other better and optimal solution for this scenerio?
http://drupal.org/project/path_redirect_import
This module has import feature out of the box.
I'm interpreting this question as a question of performance (not a question of the ease of populating many redirects). Please correct me if I've misunderstood your question.
Put redirects in .htaccess
If you're using Apache, then your alternative is to put the redirects directly into your .htaccess configurations. There should be a similar configuration option for this for IIS as well.
This still means that you would have to create the 1 to 1 mapping for each redirect you want, but the redirects are not stored in your database so it saves hits to the db.
Advantages to using Path Redirect module
Note that the Path Redirect module can log when a redirect was last accessed. This statistic/tracking can help you remove redirects that are no longer in use in the long run.
There are posts on the Path Redirect issue queue that suggest that 1000 redirects should not be a problem but every setup is different. You will need to perform your own benchmarking to check the performance of your particular site.

Dealing with 301 redirects for a brand new website

I have seen multiple articles on redirecting Urls when the site has been redesigned or Url just changed to a standard format but I need to know how to manage when the Url has no correlation to the old one.
For instance, an old Url may have been www.mysite.com/index.php?product=12 but there is no way to map that Url to the new site.
I don't want search engines to think that the page has broken so I assume the best thing to do is to 301 redirect to the home page but I am not sure how I would do that effectively. Would I just change the 404 error page to do a 301 to the home page?
Also, would that then cause issues with duplicate content via dofferent Urls?
Is it better to just not worry about these and let the search engines re-index the new Urls?
I am running IIS7 with Rewrite module and ASP.NET 2.
Thanks.
Why do you say there is no way to map that URL to the new one? There probably is, since both should be unique identifiers for a given resource. If your site has good rankings, it may be worth the pain to work this out and have a 301 redirect to the right page. In this way, the ranks should be unchanged.
Redirecting everything to the new home page will probably have a negative effect. It really depends on how the bots are going to interpret this. But it may seem an artificial way to increase the rank of the home page, and correspondingly get a penalty.
Doing nothing and waiting for the bots to index your new site will of course work, but often you cannot afford to lose the high rank you have gained.
All in all, I would advise you to ask here a new question on how to map the old URLs to the new ones, and do proper redirects.
That product URL you supplied is obviously, well, a product. The best bet is to 301 redirect it to a new page that is the most relevant to that old page. If there aren't any external links even pointing to it at all, just let it die. Be sure to remove it from any sitemaps or old navigation links you may have internally though or it will keep getting re-indexed which is what you want to avoid.
Once you have your new site structure set up, visit a site like AuditMyPc.com and create a brand new sitemap of your new site setup. Then login to Google Webmaster Tools and resubmit the new sitemap. This normally will fix the problem, but if that page is indexed, expect it to stay in Google's index for a while. They don't clean themselves up too well.