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
  • 4,077
  • 1
  • 36
  • 44

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,117
  • 1
  • 11
  • 32
0

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

RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
gmc
  • 3,707
  • 2
  • 31
  • 40
  • 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
  • This returns redirect loop in my case! anyway i accept answer in this question and thank you. – Amir Fo Mar 27 '17 at 16:48