How to add WWW to URL in php

If your site can be accessed as both http://www.domain.com/ as well as http://domain.com/ and are having trouble with things such as cookies on the Netscape browser*, here is a little rewrite rule you can place in your httpd.conf or on a per directory basis using .htaccess

Here is what happens. When you request a page such as http://domain.com/index.html, the rewrite engine checks to see if the HTTP_HOST does not match the fully qualified domain name which in this case is www.domain.com. If they do not match, the engine rewrites the URL with the SERVER_NAME value.

Create .htaccess file and write above code in this file. Access your domain as domain.com, www will add automatically with the domain like www.domain.com

Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Yes0
No0
Harinder Singh

Harinder Singh

My name is Harinder Singh and I specialize in Software industry. I consider myself as a life learner. I love learning new concepts, embracing new ideas and reading and searching for innovation.