dongpanbo4727 2012-06-23 20:06
浏览 104
已采纳

.htaccess重写为https

So I want to do the following:

  1. if the user tries to go to an ypart of the site other than index.php, they get redirected to the https version.

  2. so if they try to go to example.com/index.php they do not get redirected to the https version

  3. but if they go to any part of the site other than index.php (like welcome.php) they get redirected to the https version.

here's how I did full site https redirection before (I'm not sure how to do full site redirection to https example on index.php)

RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://www.handybook.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]


# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
  • 写回答

1条回答 默认 最新

  • dongpingwu8378 2012-06-23 21:42
    关注

    In order to have all pages except for index redirect to https, add the following to your .htaccess file:

    RewriteCond %{HTTPS} !on
    RewriteRule !^(index)\.php$ https://%{HTTP_HOST}%{REQUEST_URI}
    

    You can add additional exceptions using the pipe character within the parenthesis, like so:

    RewriteRule !^(index|about|contact)\.php$ https://%{HTTP_HOST}%{REQUEST_URI}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序