Reputation: 73
The code below works fine other than no http urls are getting redirected with full url to the https... they get thrown to root with a 301. Even http urls with section.php are getting redirected correctly to the full https url.
See here, how the http redirect doesn't work. http://www.jamavarrestaurants.com/s/6/mayfair-private-dining-with-private-room
Working here, but we don't want section.php in the url. http://www.jamavarrestaurants.com/section.php/6/mayfair-private-dining-with-private-room
NOTE: Just to confuse matters we have copied the section.php file which contains the SEF checks and URL structure and made a copy "s.php" which gets used now or should. Same for products.php, article.php and discount.php
Any help would be very much appreciated.
#Header append X-FRAME-OPTIONS "SAMEORIGIN"
RewriteEngine On
RewriteBase /
## HTTP > HTTPS (only works for this format
http://www.jamavarrestaurants.com/section.php/3/1/mayfair-restaurant )
## see: http://www.codexworld.com/redirect-non-www-to-www-http-to-https-
using-htaccess-file/
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.jamavarrestaurants.com%{REQUEST_URI} [NE,L]
## RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
# RewriteRule ^index\.php$ https://www.jamavarrestaurants.com/ [R=301,L]
#
## Added beciause the catch all 404 redirect was sending to /index
# RewriteRule ^index?$ https://www.jamavarrestaurants.com [L,R=301,NC]
#
### JSHOP CORE REWRITE RULES ###
################################
#<IfModule mod_rewrite.c>
Options +SymlinksIfOwnerMatch +MultiViews
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?).php/(.*?) $1.php?$2
## special rewrite rules for shortened urls ##
RewriteRule ^section.php/(.*) /s/$1 [R=301,L]
RewriteRule ^section/(.*) /s/$1 [R=301,L]
#
### To remove section page if 1 which is default for most (unless products
span more)
RewriteRule ^s.php/(.*)/1/(.*) /s/$1/$2 [R=301,L]
#RewriteRule ^s/(.*)/1/(.*) /s/$1/$2 [R=301,L]
#
RewriteRule ^product.php/(.*) /p/$1 [R=301,L]
RewriteRule ^product/(.*) /p/$1 [R=301,L]
RewriteRule ^article.php/(.*) /a/$1 [R=301,L]
RewriteRule ^article/(.*) /a/$1 [R=301,L]
RewriteRule ^discount.php/(.*) /d/$1 [R=301,L]
RewriteRule ^discount/(.*) /d/$1 [R=301,L]
#</IfModule>
###########################
# The rest
############################
Upvotes: 1
Views: 62
Reputation: 784958
Refactor and reorder your rules. Replace your .htaccess with this:
Options +SymlinksIfOwnerMatch +MultiViews
RewriteEngine On
RewriteBase /
## HTTP > HTTPS (only works for this format
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(\S*)\sHTTP [NC]
RewriteRule ^ https://www.jamavarrestaurants.com/%1 [NE,L,R=301]
## special rewrite rules for shortened urls ##
RewriteRule ^section(?:\.php)?/(.*)$ /s/$1 [R=301,L]
### To remove section page if 1 which is default for most (unless produccts span more)
RewriteRule ^s\.php/(.*)/1/(.*) /s/$1/$2 [R=301,L]
RewriteRule ^product(?:\.php)?/(.*)$ /p/$1 [R=301,L]
RewriteRule ^article(?:\.php)?/(.*)$ /a/$1 [R=301,L]
RewriteRule ^discount(?:\.php)/(.*)$ /d/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)\.php/(.*)$ $1.php?$2 [L,QSA]
Make sure to completely clear your browser cache before testing this change.
curl
test output:
curl -kI -A "Chrome" 'http://www.jamavarrestaurants.com/s/5/mayfair-food-and-wine-menus'
HTTP/1.1 301 Moved Permanently
Date: Mon, 20 Mar 2017 21:40:31 GMT
Server: Apache
Location: https://www.jamavarrestaurants.com/s.php/5/mayfair-food-and-wine-menus
Content-Type: text/html; charset=iso-8859-1
Upvotes: 1