[Apache] make yes.com to www.yes.com
As the title suggests, is there a way to make everyone who comes to to my site using the name mydomain.com to go to www.mydomain.com? Because I am getting javascript errors and it seems like the browser counts www.mydomain.com and mydomain.com as two different domains.
Can be done using the rewrite engine module.
I have it in a .htaccess file in the root directory, but should work in httpd.conf aswell. When someone visists mydomain.com/blah/blah, the HTTP response code 301 (file moved) is sent back with the new address www.mydomain.com/blah/blah. It changes the host name and preserves any directory and file structure in the original request. The new web page is automatically asked for by the web browser, so the change is pretty much done without the user noticing anything.
RewriteEngine OnRewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
I have it in a .htaccess file in the root directory, but should work in httpd.conf aswell. When someone visists mydomain.com/blah/blah, the HTTP response code 301 (file moved) is sent back with the new address www.mydomain.com/blah/blah. It changes the host name and preserves any directory and file structure in the original request. The new web page is automatically asked for by the web browser, so the change is pretty much done without the user noticing anything.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement