0

I am trying to redirect http to https by .htaccess But it does not work some where!

This is my domain: www.amirforsati.ir

When i use http like http://www.amirforsati.ir it redirects to https

When i use http like http://www.amirforsati.ir/want it does not redirect to https

My apache .htacces code is:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^amirforsati\.ir [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.amirforsati.ir/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^136\.243\.80\.209
RewriteRule (.*) https://www.amirforsati.ir/$1 [R=301,L]

RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
Amir Fo
  • 5,163
  • 1
  • 43
  • 51
  • http://stackoverflow.com/a/13000059/3933634 ? `RewriteEngine On` - `RewriteCond %{HTTPS} off` - `RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]` – Liberateur Mar 27 '17 at 16:29
  • @Liberateur this is an answer for Https to http redirect using htaccess – Amir Fo Mar 27 '17 at 16:34

2 Answers2

1

You can try this :

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^want.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

source : https://stackoverflow.com/a/13000059/3933634 (inverse)

Community
  • 1
  • 1
Liberateur
  • 1,337
  • 1
  • 14
  • 33
0

To redirect all requests to https, I use the following rule:

RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
gmc
  • 3,910
  • 2
  • 31
  • 44
  • i changed my code to `RewriteRule ^(.*)$ https://www.%{SERVER_NAME}%/$1 [END,QSA,R=permanent]` but still does not work – Amir Fo Mar 27 '17 at 16:30