Forum Moderators: phranque
I need to redirect it to https and I have not included the www subdomain because the Comodo certificate only goes to e.g. [example.com...] i.e without the www.
RewriteEngine on
#
# Redirect http requests for abc.php or def.php to https
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(abc|def)\.php$ https://www.example.com/$1.php [R=301,L]
#
# Redirect https requests for all resources except for abc.php,
# def.php, and [i]objects included on those pages[/i] back to http
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^(abc|def)\.php$
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
[edited by: jdMorgan at 1:19 am (utc) on Apr 30, 2010]
It is necessary to exclude these objects to avoid getting "Mixed secure/insecure content" warnings when viewing an https page with, for example, image requests being redirected to http.
Less-short answer:
RewriteEngine on
#
# Redirect http requests for abc.php or def.php to https
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(abc|def)\.php$ [example.com...] [R=301,L]
#
# Redirect https requests for all resources except for abc.php,
# def.php, and objects included on those pages back to http
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !^(abc|def)\.php$
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
The second rule is an example of one method, and works on a 'typical' site where the types of objects included on pages can be easily enumerated. It is necessary to exclude these objects to avoid getting "Mixed secure/insecure content" warnings when viewing an https page with, for example, image requests being redirected to http.
You may need to expand the list, or perhaps you can remove filetypes you don't include on your secure pages.
Jim
[edit] Corrected as noted below. [/edit]
RewriteEngine on
#
# Redirect http requests for abc.php or def.php to https
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{REQUEST_URI}>%{QUERY_STRING} ^/(index\.php)>option=com_wrapper&Itemid=38
RewriteRule \.php$ https://www.example.com/%1.php [R=301,L]
#
# Redirect https requests for all resources except for abc.php,
# def.php, and objects included on those pages back to http
RewriteCond %{SERVER_PORT} =443
RewriteCond $1>%{QUERY_STRING} !^(index\.php)>option=com_wrapper&Itemid=38
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]