♥Tsimi Posted March 19, 2018 Share Posted March 19, 2018 What should go into my htaccess file if I need to have the following redirects. 1. From example.com to https:// www.example.com/store/ (added space after // to prevent showing it as URL link) and 2. From www.example.com to https:// www.example.com/store/ (added space after // to prevent showing it as URL link) and 3. force SSL on the whole store. I think #3 can be done by adding https on HTTP_SERVER and HTTPS_SERVER inside the configure.php file. Link to comment Share on other sites More sharing options...
♥raiwa Posted March 19, 2018 Share Posted March 19, 2018 1.: # Force WWW. RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://www.yourstore.com/$1 [R=301,L] 2.: May vary depending on your server setup https://stackoverflow.com/questions/16200501/http-to-https-apache-redirection 3.: Yes, like you say About Me: http://www.oscommerce.com/forums/user/249059-raiwa/ Need help? How To Get The Help You Need Is your version of osC up to date? You'll find the latest osC community version CE Phoenix here. Public Phoenix Change Log Cheat Set on Google Sheets Link to comment Share on other sites More sharing options...
♥Tsimi Posted March 19, 2018 Author Share Posted March 19, 2018 Thanks @raiwa This here worked for me. RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://www.example.com/store/$1 [R=301,L] Link to comment Share on other sites More sharing options...
Jack_mcs Posted March 19, 2018 Share Posted March 19, 2018 You need a little more than that for SEO purposes. Here's what I suggest: #redirect index.php to root RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ RewriteRule ^index\.php$ https://www.example.com/store/ [R=301,L] #redirect non-www to www RewriteCond %{HTTP_HOST} ^example\.com RewriteRule ^(.*)$ https://www.example.com/store/$1 [R=permanent,L] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/store/$1 [R,L] You can also add the following to the roots .htaccess file . It is a stricter method to ensure ssl is used but you have to be sure the whole shop and any sub-sites will work with full ssl. This page explains it in more detail. Header always set Strict-Transport-Security "max-age=31536000; preload; includeSubDomains" env=HTTPS Also, if you use googles webmaster tools, be sure to setup an item for https if it doesn't already exist or the data for the site won't be recorded. Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
MrPhil Posted March 19, 2018 Share Posted March 19, 2018 6 hours ago, Tsimi said: 3. force SSL on the whole store. I think #3 can be done by adding https on HTTP_SERVER and HTTPS_SERVER inside the configure.php file. No, that's not sufficient. What happens when someone types in http:, or just the domain (and lets the browser add http: and //)? You also need to see if http: is being used, and redirect (R=301) to https:. Try to set up the .htaccess commands to avoid multiple R=301's (slower, and a search engine penalty) and especially to avoid accidentally creating a loop (e.g., http: to https:, and then non-www to www with http:). Link to comment Share on other sites More sharing options...
♥Tsimi Posted March 19, 2018 Author Share Posted March 19, 2018 @Jack_mcs @MrPhil Thanks guys. I will try out Jack's code once and see how that goes. @MrPhil Can show a sample code for something that would enforce or prevent from people being able to browse the shop by typing http instead of https Link to comment Share on other sites More sharing options...
MrPhil Posted March 19, 2018 Share Posted March 19, 2018 To force https (SSL) if someone should come in on http (non-SSL): RewriteEngine On [if not already on] RewriteCond %{HTTPS} !on [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R=301,L] This combines forcing SSL with forcing www. domain name. If you are dealing with multiple domain names or subdomains, this would have to be done differently. You could drop the [OR] and the www check line, and deal with domain names separately. Link to comment Share on other sites More sharing options...
♥Tsimi Posted April 10, 2018 Author Share Posted April 10, 2018 @MrPhil Redirect from www.example.com/oldstore/ to www.example.com/newstore/ What would I need to add to the htaccess file of the oldstore to redirect correctly? I have tried a few redirects that I found on stackoverflow but none seems to work. Including any product link and all the rest of the shop. As soon someone access www.example.com/oldstore/, even if typing directly the URL they should be redirected to www.example.com/newstore/ Link to comment Share on other sites More sharing options...
MrPhil Posted April 10, 2018 Share Posted April 10, 2018 One of these should work: 1) in /.htaccess RewriteEngine On RewriteCond %{REQUEST_URI} ^/oldstore RewriteRule oldstore/(.*)$ /newstore/$1 [R=301,L] RewriteRule oldstore /newstore/ [R=301,L] 2) in /oldstore/.htaccess (if your host has a defective setup that skips /.htaccess if /oldstore is a valid path) RewriteEngine On RewriteRule ^(.*)$ /newstore/$1 [R=301,L] The R=301 flag is to show the new address to the user or search engine, and encourage them to bookmark it. All this assumes, of course, that you're on a server that reads and processes .htaccess (e.g., an Apache server). You may have to do something different on, say, a Windows server. If none of this works, talk to your host's technical support to see how to do it -- maybe they have a strange setup. Link to comment Share on other sites More sharing options...
♥Tsimi Posted April 11, 2018 Author Share Posted April 11, 2018 @MrPhil No. 2 workes like a charm. Thanks again for the quick help. Link to comment Share on other sites More sharing options...
pafranklin Posted May 2, 2018 Share Posted May 2, 2018 On 19/03/2018 at 1:15 PM, Jack_mcs said: #redirect index.php to root RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ RewriteRule ^index\.php$ https://www.example.com/store/ [R=301,L] #redirect non-www to www RewriteCond %{HTTP_HOST} ^example\.com RewriteRule ^(.*)$ https://www.example.com/store/$1 [R=permanent,L] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/store/$1 [R,L] On 19/03/2018 at 1:15 PM, Jack_mcs said: #redirect index.php to root RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ RewriteRule ^index\.php$ https://www.example.com/store/ [R=301,L] #redirect non-www to www RewriteCond %{HTTP_HOST} ^example\.com RewriteRule ^(.*)$ https://www.example.com/store/$1 [R=permanent,L] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/store/$1 [R,L] Thank you for all of the help and I'm making progress. Howwever when I add the following to my .htaccess file the site crashes. RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.martinberrillsports.com/$1 [R,L] I also tried a condition from whynopadlock.com (below) and this also crashed my site. Am I doing something wrong and is the {SERVER_PORT} 80 significant in this in some way? RewriteCond %{HTTP_HOST} martinberrillsports\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.martinberrillsports.com/$1 [R,L] Thanks in advance again. I'm very grateful for the input and help! Paul You will never learn if you don't try. And boy am I trying....! Link to comment Share on other sites More sharing options...
Zzyzx1234 Posted May 2, 2018 Share Posted May 2, 2018 Did you put RewriteEngine On before it? Link to comment Share on other sites More sharing options...
pafranklin Posted May 2, 2018 Share Posted May 2, 2018 Hi, Yes I did current extract from .htaccess is: RewriteEngine On RewriteBase / RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING} RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING} RewriteRule ^(.*)-m-(.*).html$ index.php?manufacturers_id=$2&%{QUERY_STRING} #redirect index.php to root RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ RewriteRule ^index\.php$ https://www.martinberrillsportscom/ [R=301,L] #redirect non-www to www RewriteCond %{HTTP_HOST} ^example\.com RewriteRule ^(.*)$ https://www.martinberrillsports.com/$1 [R=permanent,L] However adding this next bit results in website not loading / crashing. RewriteCond %{SERVER_PORT} 80RewriteRule ^(.*)$ https://www.martinberrillsports.com/$1 [R,L] Thank you. Paul You will never learn if you don't try. And boy am I trying....! Link to comment Share on other sites More sharing options...
Zzyzx1234 Posted May 2, 2018 Share Posted May 2, 2018 Hi, Just wanted to double check, "RewriteRule ^index\.php$ https://www.martinberrillsportscom/ [R=301,L]" is missing the "." before the com. The server port might be wrong think it might need to be 443. Link to comment Share on other sites More sharing options...
Jack_mcs Posted May 2, 2018 Share Posted May 2, 2018 It might be that your server is setup to use a different variable for ssl. This thread may help: http://www.oscommerce.com/forums/index.php?showtopic=334107. It also has a link to an addon that has a test script you can run to determine the correct variable. Or you could ask your host to check it. Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
pafranklin Posted May 2, 2018 Share Posted May 2, 2018 Thank you for spotting the missing ".". I have checked and it definitely should be Port 80 but when added this seems to "break" the site. You will never learn if you don't try. And boy am I trying....! Link to comment Share on other sites More sharing options...
Zzyzx1234 Posted May 2, 2018 Share Posted May 2, 2018 It caused to many redirects when put to port 443, probably a conflict somewhere. Might be worth speaking with your host and see if they can work out why. Link to comment Share on other sites More sharing options...
MrPhil Posted May 2, 2018 Share Posted May 2, 2018 RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.martinberrillsports.com/$1 [R,L] The first thing I'd try is changing [R,L] to [R=301,L] ... maybe the server is confused by "R" alone. "80" is the normal http server port, and "443" is the normal https server port. You might try changing that line to RewriteCond %{HTTPS} !on and see if anything changes. If you also want to force "www" in the domain name, RewriteCond %{HTTPS} !on [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ https://www.martinberrillsports.com/$1 [R=301,L] Link to comment Share on other sites More sharing options...
pafranklin Posted May 2, 2018 Share Posted May 2, 2018 Hi, Thank you for the help so far - I am eternally grateful! I think I'm really close and after some input from the webhosts have the following: #redirect index.php to root #RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/ #RewriteRule ^index\.php$ https://www.martinberrillsports.com/ [R=301,L] #redirect non-www to www #RewriteCond %{HTTP_HOST} ^martinberrillsports\.com #RewriteRule ^(.*)$ https://www.martinberrillsports.com/$1 [R=permanent,L] RewriteEngine On RewriteCond %{ENV:HTTPS} !=on RewriteRule ^.*$ https://www.%{SERVER_NAME}%{REQUEST_URI} [R,L] The only remaining problem seems to be that http://www.martinberrillsports.com redirects to https://www.www.martinberrillsports.com. Please can anyone see which redirect is causing this and how to correct? Many thanks in advance. Paul You will never learn if you don't try. And boy am I trying....! Link to comment Share on other sites More sharing options...
Jack_mcs Posted May 2, 2018 Share Posted May 2, 2018 The RewriteEngine On should be above all of the redirect code. As for the redirect from http to https, that is handled by the last part - the one you just worked on. The whole idea of this change is to switch from http to https. Why are you saying it is a problem? Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
♥raiwa Posted May 2, 2018 Share Posted May 2, 2018 @Jack_mcs, he says the problem is that www gets doubled: https://www.www.martinberrillsports.com. About Me: http://www.oscommerce.com/forums/user/249059-raiwa/ Need help? How To Get The Help You Need Is your version of osC up to date? You'll find the latest osC community version CE Phoenix here. Public Phoenix Change Log Cheat Set on Google Sheets Link to comment Share on other sites More sharing options...
Jack_mcs Posted May 2, 2018 Share Posted May 2, 2018 Thanks. I was focused on the http part and didn't even notice the www. pafranklin It is caused by the www. in RewriteRule ^.*$ https://www.%{SERVER_NAME}%{REQUEST_URI} [R,L] That code is a more general approach that will work with different domain names. You don't need it for this situation. Just replace it with this (change the domain name, of course). RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons Link to comment Share on other sites More sharing options...
pafranklin Posted May 2, 2018 Share Posted May 2, 2018 Thank you everyone for your help. Very much appreciated and all working now :) Best regards. Paul You will never learn if you don't try. And boy am I trying....! Link to comment Share on other sites More sharing options...
MrPhil Posted May 2, 2018 Share Posted May 2, 2018 If the SERVER_NAME was entered by the visitor as www.example.com, simply adding www. will give you www.www.example.com. That's why you always want to hard code the domain name (server name) in the rewrite as www.example.com, rather than using %{SERVER_NAME}. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.