cancel
Showing results for 
Search instead for 
Did you mean: 

Magento2 can't access to magento2 with www but enable without www i.e domain.com

SOLVED

Magento2 can't access to magento2 with www but enable without www i.e domain.com

Hi,

I've got big problem because my page doesn't work with www but works without www i.e domain.com. I don't know why. I've written to my hosting support but they check hosting setting and tell me that everything set properly on server but it's a magento2 problem. Maybe someone had similar problem and can help me. I will be really grateful because i've looked problem for few days and i can't find.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

I've change to this lines and it works:

 

    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

I hope will works correctly finally Smiley Happy

View solution in original post

19 REPLIES 19

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

Hi@patryk_przebiro,

Can you please check once you web url in magento admin?

Admin->Store->Configuration->General->Web


Url is with www or not?


Try to update once if it is not with www. for example: https://www.weburl.com/


Are you using Apache or nginx?

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

Url is without www. When i change url to www.domain.com i can't access to domain without www Smiley Sad In chrome i've got message: "www.domain.com redirected you too many times". I'm using Apache.

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

@patryk_przebiro 

Try once the following:

You need to follow below steps :

1 ) check in system >> configuration >> Web >> Unsecure and Secure check correct url are setup or not.

2) .htaccess changes :

RewriteCond %{HTTP_HOST} ^yoursitename.com$
RewriteRule (.*) http://www.yoursitename.com$1 [R=301]

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

It's working now! But i can see http://mywebsite.com/index.php? How can i remove this index.php?

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

To remove index.php from the url:

Change following setting from the admin:
1 Stores > Configuration > Web
2 expand the Search Engine Optimization section
3 set Use Web Server Rewrites to “Yes.”
4 When complete, tap Save Config

If not work then change following in .htaccess as well.

Replace the code below:

#RewriteBase /magento/

with

RewriteBase /

Then, right after, add the following code:

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.yourdomain.com/$1 [R=301,L]
RewriteRule ^index.php/(admin|user)($|/) - [L]
RewriteRule ^index.php/(.*) $1 [R=301,QSA,L]

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

@patryk_przebiro 
Did it work for you?

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

Unfortunately not Smiley Sad Previously solution however doesn't work too Smiley Sad

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

Because i've set .htaccess configuration to earlier and only without www works. I don't know why works with www earlier ;o

Re: Magento2 can't access to magento2 with www but enable without www i.e domain.com

Revert your recently changes and then try one by one.

Clear cache and try once browser private mode.