driz Posted May 31, 2009 Share Posted May 31, 2009 Hi, I use a .htaccess file on one my websites that forces all www.domain.com to domain.com RewriteEngine OnRewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]RewriteRule ^(.*)$ http://%1/$1 [R=301,L]RewriteCond %{REQUEST_FILENAME} -f [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^(.+) - [PT,L]RewriteRule ^(.*) index.phpAddHandler php5-script .php Well ironically I have website that needs the exact opposite. If a user was to go to domain.com it auto force www.domain.comI don't understand HTACCESS at all, so any help would be very much appreciated. Thanks Link to comment Share on other sites More sharing options...
redwall_hp Posted May 31, 2009 Share Posted May 31, 2009 You could try this: RewriteEngine OnRewriteCond %{HTTP_HOST} ^www.example.com [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]RewriteCond %{REQUEST_FILENAME} -f [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^(.+) - [PT,L]RewriteRule ^(.*) index.phpAddHandler php5-script .php Link to comment Share on other sites More sharing options...
driz Posted June 1, 2009 Author Share Posted June 1, 2009 That code above is making all www.domain.com go to domain.com. I want to do the opposite. If a person was to type: http://mywebsite.com/ it would auto change to http://www.mywebsite.com/ Link to comment Share on other sites More sharing options...
jlhaslip Posted June 1, 2009 Share Posted June 1, 2009 The "www" is nothing more than a re-direct to the public, web-accessible portion of your Hosting Account.There is no need to force the inclusion of the "www" in your URL's. In fact, there is a move to drop the requirement from the process, so it is not really a wise decision, in my opinion, to do what you are doing. Link to comment Share on other sites More sharing options...
driz Posted June 1, 2009 Author Share Posted June 1, 2009 The "www" is nothing more than a re-direct to the public, web-accessible portion of your Hosting Account.There is no need to force the inclusion of the "www" in your URL's. In fact, there is a move to drop the requirement from the process, so it is not really a wise decision, in my opinion, to do what you are doing.Most websites do. For example try http://apple.com/ see how it automatically adds the WWW back on the url. same with Facebook. This is what I'm trying to do. Thanks. Link to comment Share on other sites More sharing options...
driz Posted June 22, 2009 Author Share Posted June 22, 2009 Any updates? Just to clarify I want to FORCE the www on the main domain. Thanks. Link to comment Share on other sites More sharing options...
dsonesuk Posted June 22, 2009 Share Posted June 22, 2009 try swapping it roundRewriteEngine on RewriteCond %{HTTP_HOST} ^example\.com RewriteRule (.*) http://www.example.com/$1 [R=301,L] Link to comment Share on other sites More sharing options...
driz Posted June 23, 2009 Author Share Posted June 23, 2009 try swapping it roundRewriteEngine on RewriteCond %{HTTP_HOST} ^example\.com RewriteRule (.*) http://www.example.com/$1 [R=301,L] Nailed it. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.