Forum Moderators: phranque
[edited by: jdMorgan at 3:03 pm (utc) on Jun 11, 2010]
[edit reason] Disabled smiley-faces in code [/edit]
^(login|membersection|eboardarchives)/(.*)$ ^(login|membersection|eboardarchives)/ [edited by: jdMorgan at 3:03 pm (utc) on Jun 11, 2010]
[edit reason] Changed reference to smiley-faces. [/edit]
The alternative is to have two rules ahead of the existing rules. One redirects specific requests to https at the new URL, and the other redirects specific requests to http at the new URL. They will each need a "list" like the existing two rules have.
Beware that your current ruleset uses %{HTTP_HOST} in the target and therefore does not fix any www and non-www duplicate content issues. The www.example.com hostname should be explicitly coded into the rule's target URL to fix that particular problem.
# Redirect non-SSL requests for secure pages to https
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(~([^/]+/))?((login|membersection|eboardarchives)(/.*)?)$ https://www.example.edu/$2$3 [R=301,L]
#
# Redirect SSL requests for non-secure pages to http
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^(~[^/]+/)?(login|membersection|eboardarchives)(/.*)?$
RewriteRule ^(~([^/]+/))?(.*)$ http://www.example.edu/$2$3 [R=301,L]
#
# Redirect all other ~userdir requests to /userdir/ retaining original protocol
RewriteCond %{HTTP_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^~(.+)$ http%2://www.example.edu/$1 [R=301,L]
#
# Redirect all other non-canonical hsotname requests to canonical hostname, retaining original protocol
RewriteCond %{HTTP_HOST} !^(www\.example\.edu)?$
RewriteCond %{HTTP_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^~(.+)$ http%2://www.example.edu/$1 [R=301,L]
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
The optional-subpattern "(~[^/]+/)?" you see in several places reperesents the "userdir" and its trailing slash. If it is present in the requested URL-path, it is copied into the redirect URL, dropping the leading "~".
Note that the code above depends on a big assumption. And that is that this code is placed in /userdir/.htaccess, and that URL-path-part /~userdir/ is mapped to filepath-part /userdir/ at the server config level.
# Redirect non-SSL requests for secure pages to https
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(~([^/]+/))?((login|membersection|eboardarchives)(/.*)?)$ [example.edu...] [R=301,L]
#
# Redirect SSL requests for non-secure pages to http
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^(~[^/]+/)?(login|membersection|eboardarchives)(/.*)?$
RewriteRule ^(~([^/]+/))?(.*)$ http://www.example.edu/$2$3 [R=301,L]
#
# Redirect all other ~userdir requests to /userdir/ retaining original protocol
RewriteCond %{HTTP_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^~(.+)$ http%2://www.example.edu/$1 [R=301,L]
#
# Redirect all other non-canonical hsotname requests to canonical hostname, retaining original protocol
RewriteCond %{HTTP_HOST} !^(www\.example\.edu)?$
RewriteCond %{HTTP_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^~(.+)$ http%2://www.example.edu/$1 [R=301,L]