How to fix localhost redirecting to www.localhost.com

I have got several request that when I browse the site on http://localhost/PROJECTNAME. Then it automatically redirect it to www.localhost.com/PROJECTNAME . These kind of issue can be available with almost all CMS based project like Drupal,  Prestashop, Joomla,  WordPress,  CS cart,  Magento etc..

If you are also facing this issue on your localhost then you just need to follow the instruction.

*. Open your .htaccess file (Usually found on root of the project) and comment below lines by placing # at the beginning of the file.


RewriteCond %{HTTP_HOST} !^www. [NC]

RewriteRule ^ <a href="http://www." target="_blank">http://www.</a>%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

That means simply replace these code with below code


#RewriteCond %{HTTP_HOST} !^www. [NC]
#RewriteRule ^ <a href="http://www." target="_blank">http://www.</a>%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Now save your .htaccess file and retry with browsing your project.

Related posts:

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video... Read More about Chandra Shekhar

Latest posts by Chandra Shekhar (see all)