Forum Moderators: open

Message Too Old, No Replies

How to redirect for non-www canonical in web.config?

         

abdulrahmankz

4:07 pm on Sep 14, 2024 (gmt 0)

Top Contributors Of The Month



https://example.com vs https://www.example.com
I tried to force redirect all www to non-www urls from htaccess file (server side) but not solving the issue
Google keeps chose different canonical than user instead of the rendered page is rel="canonical" is the same as url which is self-canonical (https://www.example.com)
I don't know if there is some points missing
thanks in advanced

not2easy

5:15 pm on Sep 14, 2024 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



We would need to know what you have in your .htaccess file to redirect. If we know what you have there, you can get suggestions to make it work the way you want.

abdulrahmankz

6:39 pm on Sep 14, 2024 (gmt 0)

Top Contributors Of The Month



RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

abdulrahmankz

6:43 pm on Sep 14, 2024 (gmt 0)

Top Contributors Of The Month



I'm sorry its not htaccess, according to the sever type its web.config

abdulrahmankz

6:46 pm on Sep 14, 2024 (gmt 0)

Top Contributors Of The Month



screenshot from the implemented code
https://i.ibb.co/867vrxQ/code.jpg [ibb.co]


[edited by: not2easy at 7:38 pm (utc) on Sep 14, 2024]
[edit reason] img visibility [/edit]

abdulrahmankz

7:17 pm on Sep 14, 2024 (gmt 0)

Top Contributors Of The Month



i really appreciate that, thank you
I'm a little bit confused for the issue and I'm missing a lot of points to consider in the first message

not2easy

7:21 pm on Sep 14, 2024 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I'm trying to find a reason why your screenshot does not load after moving the discussion to the IIS Forum. I'll try again to see what has changed.

Finally got something to show here. Sorry for the delay.

lucy24

4:02 am on Sep 15, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



But, but, but...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
That’s Apache, not IIS. Which of the two--the screenshot, or the posted snippet--is actually used on the site? And if Apache, is it in htaccess, in a <Directory> section, or loose in config?

The first thing to make sure of is that the coded canonicalization redirect is actually happening. You can test this easily in your browser by requesting various pages with the “wrong” form of hostname, and checking that you end up on the preferred form.

not2easy

11:47 am on Sep 15, 2024 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



@lucy24 - The screenshot and the post preceding it told me to move the discussion from the Apache forum to the IIS forum.
You can test this easily in your browser by requesting various pages with the “wrong” form of hostname, and checking that you end up on the preferred form.
Yes, then look at your logs to be sure there are no multiple redirects. When you request https://www.example.com/page.html your logs should show a 301 response and then a 200 response for https://example.com/page.html

not2easy

4:06 pm on Sep 17, 2024 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



There are some old instructions (from 2008) that explain how to redirect: [webmasterworld.com...]
- to paraphrase from that thread:
The way to do that is create a new separate website entry and then on the "Home Directory" tab

Select A redirection to A URL
https://example.com

And tick A permanent redirection for this resource.
I can't tell you whether that is accurate current information, but you should be able to ask the host how to set it up.