croakingtoad
06-26-2006, 11:17 AM
I just want to use htaccess to redirect anyone who does not add the 'www' to the url to add the 'www'. (For session purposes).
So http://domain.com/ would become http://www.domain.com/
Thanks!
ThatScriptGuy
06-26-2006, 11:26 AM
This one adds the www
Options +FollowSymlinks
rewriteEngine On
rewriteCond %{HTTP_HOST}!^(www\.¦$) [NC]
rewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This one adds the trailing slash (I've used it for http auth...no trailing slash = two login boxes IIRC)
rewriteEngine On
rewriteCond %{REQUEST_URI}\\/%{HTTP_HOST}/www. ^/+(.+/)?[^.]*[^/]\\(/)([^w][^w][^w][^.].*/(www\.)¦.*)$ [OR,NC]
rewriteCond %{HTTP_HOST}/www. ^(/)?(/)?([^w][^w][^w][^.].*/(www\.))$ [NC]
rewriteRule ^ http://%4%{HTTP_HOST}%{REQUEST_URI}%2 [L,R=301]
Kevin
croakingtoad
06-26-2006, 07:56 PM
This one adds the www
Options +FollowSymlinks
rewriteEngine On
rewriteCond %{HTTP_HOST}!^(www\.¦$) [NC]
rewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Kevin
I added the above to my .htaccess file but it isn't working?
The actual url is something like this-- http://www.domain.com/cart/
Do I need to add that cart/ in the htaccess file?
ThatScriptGuy
06-26-2006, 07:58 PM
No, you don't need /cart. That code should grab the requested HOST, if it doesn't have www on the front of it, add www and then finish off the redirect with the requested URI....
Perhaps someone else can chime in here.
Kevin
RewriteCond %{HTTP_HOST} !^www\.$ [NC]
RewriteRule /?(.*) http://www.domain.com/$1 [L,R]
Might try this? (untested)