If I set up HSTS on a domain that already implements a 301 redirect, which will take precedence? - .htaccess

Ok, so the scenario is that we have a http domain which currently uses a 301 redirect, we want to change this domain to no longer 301 redirect, and instead to be the main domain for said website.
The problem here is that 301 redirects are cached forever, so this isn't really feasible.
We do however want to change the domain to run on https only, and the https domain doesn't have any redirect set whatsoever.
So I'm wondering if I implement HSTS on a domain that already implements a 301 redirect, will the user be forwarded to the HTTPS version of the page (which currently has no redirect in place). This is presuming that they've already got the 301 redirect cached in their browser.
Unfortunately I can't seem to find any information about whether HSTS or the cached 301 redirect would take precedence.

HSTS should take precedence as that happens in the browser - before any message is sent (or any cached redirect is used in place of a request being sent).
However this is easily enough tested so would suggest you confirm it yourself.
And yes I really wish browsers would honour cache expiry times of 301s and/or expiry them periodically. Pretty annoying.

Related

Partial 301 redirects & SEO strategy

This is somewhat of a subjective question. But would like the communities take on this. My client is doing a site split. www.domain1.com will turn in to -- www.domain1.com + www.domain2.com. I know this isn't typically advisable from an SEO perspective, but they are doing it for legal reasons.
Our plan is to only rip out the product pages on www.domain1.com and add those on www.domain2.com everything else on domain1 will stay and everything else on domain2 will be original content. So here's the question, still a good idea to do single page 301 redirects for the pages that are transferred?
www.domain1.com/apples > www.domain2.com/apples
I know that's a bit open-ended, without a ton of detail, but if you have specific examples of where you've done something similar, I'd be curious to know what worked/didn't.
Yes, with a clarification: http 301 is the best for your purpose, because it means permanent redirect (good for SEO, you pass the page and domain authority, link juice...); instead a 302-redirect (http 302) means a temporary redirect, you have no time limits but all the SEO value won't pass! For your purpose, you don't want that.
In general, all pages should be redirected with http 301. Aniyway, with data analysis you can make a decision: if you have a page unuseful, with no traffic, it doesn't need to be redirected, you can use http 404 or http 410 (you can build also a custom 404 page!).
The last thing, must avoid multiple redirects, for example: instead of site1-->site2-->site3 you just need to do: site1-->site3. The reason is each redirect hurts loading speed (also the most common and useful redirect, from http to thhps!!). You just need to avoid multiple ones.

Redirect full http-link to https-domain on another server

I'm not sure if this even is possible to do, but I have two different domains on two different webservers. Both have a SSL-certificate. What I need is for all links on domain1 (both http and https) to be redirected to domain2 with https. Example:
http://domain1.com/customlink should be redirected to https://domain2.com/customlink
Also https://domain1.com/customlink should be redirected to the same as above.
Is this possible to achieve by having a .htaccess file with some rules on the webserver of domain1.com? It is important that whatever the user writes after domain1.com, also will be kept in the new redirected link.
I'm not sure if this even is possible to do .... my host told me that you cannot redirect https://example.com/SOMETHING and keep the part after slash onto the new domain
I feel there must be something more to this question, as otherwise, this is just a standard domain redirect...
two different domains on two different webservers
Both have a SSL-certificate.
Assuming there is only 1 domain (ie. domain1.com) hosted on the first server that you want to redirect.
Then, in your .htaccess file at domain1.com, use a mod_alias Redirect:
Redirect 302 / https://domain2.com/
You should remove all other directives in the .htaccess file at domain1.com in order to avoid potential conflicts (they aren't being used anyway, since you are redirecting everything).
The mod_alias Redirect directive is prefix-matching, and everything after the match is passed on to the target. eg. /foo/bar/baz is redirected to https://domain2.com/foo/bar/baz. Everything (HTTP and HTTPS) is redirected to domain2.com (HTTPS).
This is currently a 302 (temporary) redirect. Only change to a 301 (permanent) - if that is the intention - once you have confirmed this works as intended. This is to avoid any potential caching issues.

how to trash a cached http 302 response

I had an old website that permanently redirected (HTTP 302) all traffic from http://example.com/ to http://exmpale.com/drupal
now I re-implemented the entire website on wordpress but the old redirection is still cached on my user's browsers and breaking my revisiting users' experience (for some assets only).
I was thinking of adding to my new website a route serving as /drupal that will force the browser to trash the cache, is there a way to do so? maybe some http headers/javascript to trash the cache?
what do you think?
(BTW, I'm on a hosted service so my options are limited to php / .htaccess / javascript but I can't change http server configurations)
You said :
permanently redirected (HTTP 302)
But it's either:
temporary redirect (HTTP 302)
permanent redirect (HTTP 301)
302 responses are usually not cached in browsers. If you were using 301 response code this could be stored until the user close the browser. If you have problems with your users it certainly means you were using 301, but if it is not the case it means something between you and the final user is storing a cache of the redirection (like a reverse proxy cache in front of your server?).
If you were using a 301 you might try to add a temporary redirect on /drupal to /. But this may create an inifinite redirection loop on the browsers. You can maybe prevent it by adding a fake argument on the redirection, like redirectiong to /?redir=fix.

Force browsers to forget cached redirects?

I inherited a domain that previously had a 301 redirect from the root ("/") to "/index.shtml"
I've removed the redirect and a different site on the domain, but people who visited the site in the past will have the redirect behavior cached in their browsers... for a terribly long time, unless they manually clear their caches.
Anyone trying to go to example.com in these browsers will be sent to example.com/index.shtml before they even make any HTTP requests. Right now this is a huge problem because there is no index.shtml, but is there something I can do with headers to tell browsers to "forget about that redirect you just did!"?
The short answer: There is no way to tell the browsers of the users to "forget" the R 301 redirect. 301 means permanent, it can be only undone on action of the user or when the cache expires.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2
Similar Q and A on Stackoverflow:
Apache - how to disable browser caching while debugging htaccess,
Cannot remove 301 redirect
Try to avoid 301 redirects and use 302 (temporarily) instead. Here is an article how to set no cache for 301 redirects (didn't try it):
https://github.com/markkolich/blog/blob/master/content/entries/set-cache-control-and-expires-headers-on-a-redirect-with-mod-rewrite.md
What you could do in your scenario: You could add a header redirect to the file index.shtml, which sends the user to the original file, where he should usually go.
This can be done by a clear data-only cache.
It can remove all,.htaccess redirects changes from the browser.

What happens under the hood when URL's change in browser while loading

When my browser loads "wikipedia.com" it will replace it by "http://www.wikipedia.org".
How does my browser know it has to change ".com" in ".org"? I assumed this was DNS related but I was not able to find any DNS record that provides a link from "wikipedia.com" to "wikipedia.org". This happens in all major browsers.
Can anyone explains what happens under the hood?
It's just a simple server side 301 permanent redirect. There's a script on wikipedia.com which redirects all requests to wikipedia.org by sending the 301 status code:

Resources