Search code examples
magentourlhttp-redirecturl-routing

URL redirects to hompage when typed without www


Having a small issue with my website, any help would be very appreciated.

If I type a url such as website.com/feedback
It redirects to the homepage.

But typing www.website.com/feedback
It goes to the page as I want it to.

From Googling, I understand this is a .htaccess issue - but I'm a little unsure of what code to add or change. I'm find with the website displaying as www.website.com in the address bar - so I think I need to redirect non-www. urls to www. urls ?

I'm using Magento.


Solution

  • So the problem is that Magento is not keeping the path, i. e. /feedback but sending you to the homepage instead when calling the non-WWW version of your site.

    You could add this to your .htaccess

    RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    

    It redirect all non-WWW requests to WWW request while keeping the path/sub page originally called.