gatsby-plugin-htaccess icon indicating copy to clipboard operation
gatsby-plugin-htaccess copied to clipboard

Redirect all non-www to www

Open mathildebuenerd opened this issue 4 years ago • 3 comments

I would like to redirect all non-www urls to www. I have issues with configuring the plugin in gatsby-config to acheive that. At the moment I cannot succeed in doing it, whenever I go to mydomain.com, I get a "Server not found" error and no redirection.

What I would put in the .htaccess would be the following code (it also redirects from http to https):

<IfModule mod_rewrite.c>
	RewriteCond %{HTTPS} off [OR]
	RewriteCond %{HTTP_HOST} !^www\. [NC]
	RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
        RewriteRule (.*) https://www.mydomain.com/$1 [R=301,L]
</IfModule>

Is it supposed to be done only with setting the www option to true?

{
  resolve: "gatsby-plugin-htaccess",
  options: {
    https: true,
    www: true,
    host: "www.mydomain.com",
 },

I have also tries with adding the redirect, but I still have no result:

{
  resolve: "gatsby-plugin-htaccess",
  options: {
    https: true,
    www: true,
    host: "www.mathildebuenerd.dev",
    redirect: ["RewriteRule (.*) https://www.mydomain.com/$1 [R=301,L]"],
  },
},

What would be the correct way to configure this?

mathildebuenerd avatar May 23 '20 07:05 mathildebuenerd

I'm also facing this issue right now. To solve it temporarily, I edited the .htaccess after the build process was done.

Would definitely be nice if this issue gets solved. 👍

kkroeger93 avatar Oct 16 '20 11:10 kkroeger93

same here. could not able to figure it out. Any help is extremely valuable. 😊 Thanks in advance

teamrdx avatar Apr 28 '21 14:04 teamrdx

Is there anybody to help us about this?

koctalha avatar Jun 12 '21 23:06 koctalha