2

I have this htaccess:

RewriteBase /
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/my
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/my
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
DirectoryIndex index.php index.cgi index.html
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
#### PERSISTENT CONTENT ####
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ zyro/$1 [L,QSA]

and I want to know how to keep this code working and add HTTP-HTTPS redirection, any help is appreciated. Thank you

Marc Barbeau
  • 826
  • 10
  • 21
Hitshot
  • 31
  • 8

2 Answers2

1

Try this. Add to your .htaccess

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Jack
  • 985
  • 7
  • 11
  • Why would you need to restart you server after a htaccess change? – bassxzero Jun 21 '16 at 21:44
  • Not necessary unless OP is modifying any .conf apache file or if OP hasn't added the mod rewrite module to apache. I've updated original response. – Jack Jun 21 '16 at 21:48
  • I tried it and it didnt work, here is what the new file looks like – Hitshot Jun 21 '16 at 22:36
  • `RewriteBase / RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} ^/my RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !^/my DirectoryIndex index.php index.cgi index.html ErrorDocument 401 "Unauthorized" ErrorDocument 403 "Forbidden" ErrorDocument 404 /zyro/404.php #### PERSISTENT CONTENT #### RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ zyro/$1 [L,QSA]` – Hitshot Jun 21 '16 at 22:36
  • Not just on chrome but all web browsers – Hitshot Jun 21 '16 at 22:58
0

You can use the https protocol if you have a SSL certificate and have installed it correctly. Most websites use the http protocol as a default protocol to handle all the information. You can force your website to use the https protocol by creating or modifying an “.htaccess” file in the folder (e.g. root) where you want the redirect to happen.

Please add this to the .htaccess file

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Explanation

We are using three command in the code above: RewriteEngine, RewriteCond and RewriteRule. The “RewriteEngine On” tells Apache we are going to use mod_rewrite. The “RewriteCond %{HTTPS}” off, check if the the https protocol already in use. If the https protocol is use then the last line (RewriteRule) wont apply. The last line “RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}” tell the server to only rewrite the first part (http://) to (https://).

Pankaj Upadhyay
  • 2,114
  • 21
  • 22