【问题标题】:issues width htaccess redirect to https问题宽度 htaccess 重定向到 https
【发布时间】:2017-08-20 11:14:09
【问题描述】:

我正在尝试通过 .htaccess 将 http 重定向到 https 但它在某些地方不起作用!

这是我的域名:www.amirforsati.ir

当我像 http://www.amirforsati.ir 这样使用 http 时,它会重定向到 https

当我像 http://www.amirforsati.ir/want 这样使用 http 时,它不会重定向到 https

我的 apache .htacces 代码是:

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]

【问题讨论】:

  • stackoverflow.com/a/13000059/3933634 ? RewriteEngine On - RewriteCond %{HTTPS} off - RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  • @Liberateur 这是使用 htaccess 将 Https 重定向到 http 的答案
  • 是的,请阅读我的回复;)(我在代码中反转帖子)

标签: apache .htaccess


【解决方案1】:

要将所有请求重定向到 https,我使用以下规则:

RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

【讨论】:

  • 我把代码改成了RewriteRule ^(.*)$ https://www.%{SERVER_NAME}%/$1 [END,QSA,R=permanent],但还是不行
  • 这会在我的情况下返回重定向循环!无论如何,我接受这个问题的答案,谢谢。
【解决方案2】:

你可以试试这个:

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

来源:https://stackoverflow.com/a/13000059/3933634(反向)

【讨论】:

  • 谢谢大师!
猜你喜欢
  • 2018-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-30
  • 2020-09-27
  • 1970-01-01
相关资源
最近更新 更多