Home > Back-end >  I didn't IIS rewrite old domain to new domain using 301 permanently
I didn't IIS rewrite old domain to new domain using 301 permanently

Time:10-07

sorry my bad English. I had searched everywhere and tried what I found articles but didn't working all parts. I had olddomain.com without ssl cert. And I bought new domain as newdomain.com with ssl.

I want to:

  1. Redirect all olddomain.com to newdomain.com with https
  2. Redirect https://olddomain.com to https://www.newdomain.com
  3. Redirect all http or https://newdomain.com to https://www.newdomain.com

I apply following codes in web-config. Its working correctly when I tried in server. But didn't work google console and in my any browsers include mobile.

 <rewrite>
    <rules>
            <clear />
            <rule name="Force WWW, SSL and NewDomain" enabled="true" stopProcessing="true">
              <match url="(.*)" />
              <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="(http://)?(www)?olddomain\.(com)" />
                    <add input="{HTTP_HOST}" pattern="(https://)?(www)?olddomain\.(com)" />
                    <add input="{HTTP_HOST}" pattern="^[^www]" />
                    <add input="{HTTPS}" pattern="off" />
              </conditions>
              <action type="Redirect" url="https://www.newdomain.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
            </rule>
    </rules>
</rewrite>

In this case, when I try to:

  1. olddomain.com --> https://olddomain.com or www.olddomain.com --> https://olddomain.com Doesn't work.
  2. olddomain.com/tr/ --> https://www.newdomain.com/tr/ Working correctly.
  3. newdomain.com/ --> https://www.newdomain.com/tr/ Working correctly.

Here is the real one for you : When I open this address, http://www.gurmeliquid.com/tr/elektronik-sigara-likit-antalya it's change and redirect this address and not correctly working https://www.gurmeliquid.com/tr/elektronik-sigara-likit-antalya

But, I open this address, http://www.gurmeliquid.com/tr/elektronik-sigara-likit-cesitleri its change and redirect this addres correctly https://www.gurmeliquids.com/tr/elektronik-sigara-likit-cesitleri

So, what happened, where am I doing wrong?

CodePudding user response:

You have local caching issues.

Your web.config looks fine to me & http://www.gurmeliquid.... is redirecting correctly for me to https://www.gurmeliquids....

Request:

GET /tr/elektronik-sigara-likit-antalya HTTP/1.1
Host: www.gurmeliquid.com

Response:

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Location: https://www.gurmeliquids.com/tr/elektronik-sigara-likit-antalya
Server: Microsoft-IIS/10.0
Date: Wed, 06 Oct 2021 13:32:06 GMT
Content-Length: 186

I believe the cause is that you've been testing out multiple web.config variations which returned a 301 Moved Permanently previously for other endpoints.

Your browser(s) will permanently "cache" this and your only way around it is to redirect to the same endpoint twice server-side or clear local cache.

Clearing cache differs for various browsers but for Chrome, open up the "Network" tab in developer tools (F12), load the page and then right-click on the request and select "Clear browser cache". Refresh and hopefully, it'll work.

If that doesn't work, your only way is a redirect loop.

When the browser detects a redirect loop, it'll attempt to clear its cache and get the latest URI location from the server so try redirecting back twice in case your browser has cached previous development web.configs pointing to other endpoints.

Try clearing cache in your browser first before resorting to a temporary double redirect to fix your issue.

  • Related