issue in unifying domain.com with www.domain.com using 301 redirect - http-status-code-301

My company website is with ASP.NET 2.0 and one day the marketing guy ask me to unify domain.com to www.domain.com so that if visitors visit domain.com they will be redirected to www.domain.com and the status code must be 301 (301 Moved Permanently). He asks me to verify with http://www.redirect-checker.org/. In this site if we input domain.com and click Analyse button, if we have "Status: 301 Moved Permanently" then it's ok.
I tried with so many methods (using URL_Rewrite muldule with Canonical redirect, setup domain.com and redirect to www.domain.com, add rule to web.config file) and all of the methods work fine. However, I only have "Status: 301 Moved Permanently" for the first times access to the site. A second times when I access I see the site be redirected correctly to www.domain.com but the header is "HTTP/1.1 200 OK" but NOT "Status: 301 Moved Permanently" anymore.
Could you please help me how to always have "Status: 301 Moved Permanently"?
Thank you in advance

Related

301 redirect in htaccess doesn't work. What am I doing wrong?

I've made an htaccess file, but several testers tell me it's not right.
Domain B is going offline and I want to redirect all the pages to new pages on domain A.
This is the code:
redirect 301 / https://domain-A.com/
redirect 301 /page-1/domain-B/ https://domain-A.com/page-1/
redirect 301 /page-2/domain-B/ https://domain-A.com/page-2/
redirect 301 / https://domain-A.com/
redirect 301 /page-1/domain-B/ https://domain-A.com/page-1/
redirect 301 /page-2/domain-B/ https://domain-A.com/page-2/
Your rules are in the wrong order. The Redirect directive is prefix-matching. The first rule redirects everything (and preserves the URL-path). The second and third rules are never processed. (What exactly is the "tester" reporting? Is this a thrid party tool or a real "tester" person?)
If you request /page-1/domain-B/ you will see that you are not redirected as intended. (You are redirected to https://domain-A.com/page-1/domain-B/, not https://domain-A.com/page-1/ as would seem to be the intention.)
You need to reverse the order of these rules. The most specific needs to be first.
For example:
Redirect 301 /page-1/domain-B/ https://domain-A.com/page-1/
Redirect 301 /page-2/domain-B/ https://domain-A.com/page-2/
Redirect 301 / https://domain-A.com/
You will need to clear your browser cache before testing since the erroneous 301s will have been cached by the browser. Test first with 302 redirects to avoid caching issues.
/page-1/domain-B/
And /domain-B/ is actually in the URL-path?

301 redirects clashing possibly with CloudFlare

My old 301 redirects in .htaccess are no longer working because something is redirecting things twice. Example of redirect:
Redirect 301 /oldpage.html //www.example.com/newpage.php
This used to work, but now it goes to:
https://www.example.com//www.example.com/newpage.php
In CloudFlare, I have a Page Rule for the www redirection:
https://example.com/*
Forwarding URL (Status Code: 301 - Permanent Redirect, Url: https://www.example.com/$1)
And my "Always Use HTTPS" in CloudFlare is on. What could be causing the double redirect?
I put one of the URLs into a redirect checker http://www.redirect-checker.org/
and noticed that for some reason the URLs go back to http, then back to https again. So I went back and edited my .htaccess file to explicitly include the https:
Redirect 301 /oldpage.html https://www.example.com/newpage.php
And now the redirect works as expected, at least in the incognito window. The regular browser isn't yet reflecting the change.

301 redirect from one domain to another but only for specific pages

We are rebuilding a website for a client from ASP to WordPress. This website will have a different domain, url structure, and file extension. I am only just getting my head around htaccess 301 redirects, and I know enough that I can't do the following:
Redirect 301 http://www.site1.com/about_us.asp https://site2.com/about/
Redirect 301 http://www.site1.com/art-specs/ https://site2.com/specs/
Redirect 301 http://www.site1.com/page/product1/ https://site2.com/product1/
There are about 12 links in total that need to be redirected, and I want to make sure that it is done right the first time as a client's SEO rankings are on the line.
Is there a variation of the above format that I could use? Or a rewrite rule that needs to be done first? Any help (and explanations) would be greatly appreciated!
After looking more into it, I realised that the htaccess file shouldn't need anything other than relative access to the original domain.
i.e. You shouldn't need to declare: http://www.site1.com/about_us.asp since the server and domain should be configured in such a way that /about_us.asp means the same thing.
So the correct answer would be to:
[1] Configure the server (in my case cPanel) by having the original domain added as an addon domain (e.g http://www.site1.com/).
[2] In the htaccess file I would add each of the 301 redirects to the htaccess file:
Redirect 301 /about_us.asp https://site2.com/about/
Redirect 301 /art-specs/ https://site2.com/specs/
Redirect 301 /page/product1/ https://site2.com/product1/
...for each redirect
[3] And finally, adding the following to the bottom of the htaccess file will catch everything else and redirect them to the home page:
RedirectMatch 301 .* https://site2.com

Redirect entire site to other url with htaccess

I have a site which you can access with or without https rule. So, I need to make a redirect to another page. Example:
My website is: www.google.com so I can access by the moment as https://www.google.com and http://www.google.com but I need when you get into my website trough http or https way you must have to redirect to www.yahoo.com.
Besides I need the url redirection too to any subdomain or url which exists in http://www.google.com or https://www.google.com
How can I do this? I have no found alredy information about it in S.O. Thanks.
Very simple. You can use the following Redirect in your htaccess to redirect all requests from your site to the other domain
RedirectMatch 301 / http://yahoo.com/

How to redirect all traffic to non www https with .htaccess

I have domain registered in ovh. My site files are stored in folder called "www" in root directory. It was original ovh setup. A few days ago I discovered that i can use let's encrypt ssl certyficate. Now I have these addresses:
example.com,
www.example.com,
https://example.com,
https://www.example.com
I want to redirect:
example.com
www.example.com
https://www.example.com
to:
https://example.com
via .htaccess 301 redirection
I tried a lot of sample htaccess redirections from this and other sites. Non of them work perfectly for me.
For example redirection from example.com to https://example.com was ok, but from www.example.comtake me tohttps://www.example.com/wwworhttps://www.example.com with browser warning "unsafe content".
It is harder than i thought.
If you're using wordpress, you could install a simple pulgin called Really Simple SSl which will automatically do this redirection.

Resources