943,542 Members | Top Members by Rank

Apr 23rd, 2009
0

.htaccess - remove www. except when https

Expand Post »
Hello,

I am trying to remove the www. at the beginning of our domain name via .htaccess. I'm doing it like this:
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R,NC]
It seems to word wonderfully.

I would like to retain the www. when someone accesses the site securely with https. I found a bit of code on the web that described how to force the www. except on a certain folder ("blog" in this case):
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule !^blog(/.*)?$ http://www.domain.com%{REQUEST_URI} [R,L]

I thought if I changed it a little, I could make at least a single folder keep the www. like this:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule !^secure(/.*)?$ http://.domain.com%{REQUEST_URI} [R,L]

It didn't work. I got a redirect loop error.

Any ideas?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bigtalk is offline Offline
16 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Linux Servers and Apache Forum Timeline: HTTP Auth (.htpasswd) Not Working In CGI-BIN
Next Thread in Linux Servers and Apache Forum Timeline: First openSUSE Community Week Starts Monday





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC