-1

I'm trying to redirect all the requests from https://mywebsite.com to https://www.mywebsite.com (Wordpress Website).

I activated SSL and used the "Really Simple SSL" plugin to enable https. Redirect from http://www.mywebsite.com to https://www.mywebsite.com works nice.

But when I write the website without www, it doesn't work. I tried to add to my .htaccess lots of code from tons of website to redirect non-www to www URL but it doesn't work. I think is unuseful to paste here all the .htaccess configuration I tried to make things work but nothing. Please help me :(

MurugananthamS
  • 2,395
  • 4
  • 20
  • 49

2 Answers2

0

I think you can find answers on google easily, like https://wordpress.org/support/topic/forcing-http-to-https-and-non-www-to-www/ The last post tells you what to do, add this to top of your .htaccess (found on FTP in root of your Wordpress site):

RewriteEngine on
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]

(NOTE: Make sure you change www.example.com to your domain.)

Also, are you certain any of the changes you made to .htaccess have changed any outcomes? Some hosting companies require you to push changes to .htaccess by pressing a button in the backend. Or else changes to the .htaccess have no effect.

Update

Ok, that it is running on Windows server is very relevant to mention here. .htaccess does not work on Windows server.

Can you try what is mentioned here?: IIS Redirect non-www to www AND http to https

So put this in web.config: (dont forget to replace zzz.com with your website)

<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^[^www]" />
      <add input="{HTTPS}" pattern="off" />
  </conditions>
  <action type="Redirect" url="https://www.zzz.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
Snuwerd
  • 459
  • 3
  • 6
  • Hi, thanks for the answer. Yes, I've already used that `.htaccess` and put it on top, but it didn't work. I'm using IIS Server so I discovered that i can also use`web.config` file to do https and www redirect, but it didn't work again. When i added this rules: ` `website go off showing 500 err – giovinazzo17 Nov 21 '19 at 12:57
  • Update: i've added another answer where i show my web.config file. Thanks for help. – giovinazzo17 Nov 21 '19 at 17:57
0

Reply to the update: It doesn't work. Maybe i have to wait hours to have effects? Maybe i have to change something in IIS settings? That's my web.config file.

        <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <clear />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <clear />
                <rule name="WordPress Rule" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
<rule name="Force WWW and SSL" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAny">
      <add input="{HTTP_HOST}" pattern="^[^www]" />
      <add input="{HTTPS}" pattern="off" />
  </conditions>
  <action type="Redirect" url="https://www.mywebsitename.it/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
            </rules>
            <outboundRules>
                <clear />
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>
  • As a sidenote, are you renting webspace from a hosting company? This is generally something the hosting company can help you with, your request is quite basic. And yes, I can imagine you have to wait sometimes. – Snuwerd Nov 21 '19 at 18:23
  • 1
    Yes, i'm gonna ask them. An interesting thing i noticed is that if i write on mobile `http://mywebsitename.it` it takes me to `https://www.mywebsitename.it `, if i do the same on chrome (Desktop), it takes me to `https://mywebsitename.it`, and so it doesn't work. In case of `https://mywebsitename.it`, it doesn't work at all (mobile and desktop). I'm gonna update you after calling customer service. Thank you. – giovinazzo17 Nov 21 '19 at 19:22