We moved the the whole site from http:// to https:// this works fine if you arrive at the site via https://. However all the previously cached urls (in Google) on http:// need to be redirected. Also we had previously been using a rewrite to take out .php in the urls and want to keep this. But this is where we are having problems.
The redirect we have from http to https pages in whole site which works with the htaccess below, but it does not remove the .php extension on those redirects.
Have tried these
Force HTTPS on certain URLs and force HTTP for all others
Here is the problem
Here is an example old url, see how it get rewriiten with .php not removed.
http://www.myitalianliving.com/product/1105/translucent-stackable-indoor-outdoor-chair-cooler-by-scab
Here is the site
https://www.myitalianliving.com/
Here is the .htaccess file
RewriteEngine on
## provide ip address redirect to canonical and SEO puproses
## see: https://stackoverflow.com/questions/9985735/redirect-ip-to-domain
#
#RewriteCond %{HTTP_HOST} ^81.29.78.50$ [NC,OR]
#RewriteCond %{HTTP_HOST} ^([a-z.]+)?myitalianliving.com$ [NC]
#RewriteCond %{HTTP_HOST} !^www. [NC]
#RewriteCond %{SERVER_PORT} 80
#RewriteRule ^(.*)$ https://www.myitalianliving.com/$1 [R=301]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.php HTTP/
RewriteRule ^index.php$ https://www.myitalianliving.com/ [R=301]
RewriteRule ^index.html$ https://www.myitalianliving.com/ [R=301]
RewriteRule ^index.htm$ https://www.myitalianliving.com/ [R=301]
## added below as in testing we had just the .com/index in the url no extension.
RewriteRule ^index https://www.myitalianliving.com/ [R=301]
#
##########################
# Try to remove .php AND send to https from http connection
##########################
Options +SymlinksIfOwnerMatch +MultiViews
#
#### RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##### RewriteRule ^(.*).php/(.*) $1.php?$2
RewriteRule ^(.*?).php/(.*?) $1.php?$2 [NC]
#
## https://stackoverflow.com/questions/4398951/force-ssl-https-using- htaccess-and-mod-rewrite
#
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
2
Answers
Moving HTTPS redirect to the top worked with the following redirect at the bottom.
You need to move your HTTPS redirect to the top of your set of rules:
Additionally, you need to add conditions to the index redirect rules and use the
L
flags (just in case).