Forum Moderators: phranque
RewriteEngine On
RewriteBase /
#
# Redirect non-SSL requests for secure pages to HTTPS URL, fixing missing trailing slash as well
RewriteCond %{SERVER_PORT} !=443
RewriteCond $1 ^(our-wines/order-wines)/?$ [OR]
RewriteCond $1 ^(our-wines/order-holiday-wine-gifts)/?$ [OR]
RewriteCond $1 ^(wine-club)/?$
RewriteRule ^(.+)$ https://www.example.com/%1/ [R=301,L]
#
# Redirect SSL requests for non-secure objects back to HTTP,
# except for objects shared between SSL and non-SSL pages
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
RewriteCond $1 !^our-wines/order-wines/?$
RewriteCond $1 !^our-wines/order-holiday-wine-gifts/?$
RewriteCond $1 !^wine-club/?$
RewriteRule ^(.+)$ http://www.example.com/$1 [R=301,L]
#
# Redirect SSL requests for secure pages to add missing trailing slash
RewriteCond %{SERVER_PORT} =443
RewriteCond $1 ^our-wines/order-wines$ [OR]
RewriteCond $1 ^our-wines/order-holiday-wine-gifts$ [OR]
RewriteCond $1 ^wine-club$
RewriteRule ^(.+)$ https://www.example.com/$1/ [R=301,L]
#
# Redirect non-SSL extensionless-URL requests to add missing trailing slash
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(([^/]+/)*[^./]+)$ http://www.example.com/$1/ [R=301,L]
#
# Redirect direct client requests for "/index.php" at any directory level back
# to the canonical "/" URL in that directory, preserving requested protocol
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)+index\.php([?#][^\ ]*)?\ HTTP/
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(([^/]+/)*)index\.php$ http%2://www.example.com/$1 [R=301,L]
#
# Redirect non-blank, non-canonical hostname requests to canonical
# hostname, preserving requested protocol and URL-path
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ http%2://www.example.com/$1 [R=301,L]
#
# BEGIN WordPress
# Internally rewrite requests which do not resolve to a physically-existing file or directory
# to the WordPresss script, excluding requests for objects which WP does not create/generate
# and the WP script itself from these 'exists' checks to greatly improve server efficiency
RewriteCond %{REQUEST_URI} !(^/index\.php|\.(gif|jpe?g|png|ico|css|js))$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# End Wordpress