0

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]
Community
  • 1
  • 1
Puzzel
  • 65
  • 1
  • 6
  • you may refer those links http://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess and http://stackoverflow.com/questions/4398951/force-ssl-https-using-htaccess-and-mod-rewrite – Ashok Chandrapal Aug 18 '15 at 16:00

2 Answers2

0

You need to move your HTTPS redirect to the top of your set of rules:

RewriteEngine on

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

## provide ip address redirect to canonical and SEO puproses
## see: http://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/ [L,R=301] 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html?\ HTTP/ 
RewriteRule ^index\.html?$ https://www.myitalianliving.com/ [L,R=301] 
## added below as in testing we had just the .com/index in the url no      extension.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\ HTTP/ RewriteRule ^index https://www.myitalianliving.com/ [L,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 [L,NC]

Additionally, you need to add conditions to the index redirect rules and use the L flags (just in case).

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
0

Moving HTTPS redirect to the top worked with the following redirect at the bottom.

# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

# Rewrite URLs for processing by router (article.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/(.+)$ article.php?url=$1 [QSA,L]

# Rewrite URLs for processing by router (product.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product/(.+)$ product.php?url=$1 [QSA,L]

# Rewrite URLs for processing by router (page.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^page/(.+)$ page.php?url=$1 [QSA,L]

# Rewrite URLs for processing by router (section.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ section.php?url=$1 [QSA,L]
Puzzel
  • 65
  • 1
  • 6