apache - 在 .htaccess 中强制 https 与 URL 重写冲突
问题描述
这是我的.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
目前正在发生的事情如下:
http://somesubdomain.mydomain.com/param1/param2
被重定向到:
https://somesubdomain.mydomain.com/index.php?params=param1/param2
显然我希望它被重定向到
https://somesubdomain.mydomain.com/param1/param2
谢谢
解决方案
更改顺序解决了问题:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?params=$1 [L,QSA]
推荐阅读
- spring - 在应用程序上下文中将 Spring Boot 2.1.9 碰撞到 2.2.0 没有 AuthenticationManager
- html - 如何修改下拉列表?
- javascript - ngClass 混合条件
- python - 将图像保存到后台任务抓取的 ImageField
- mongodb - Pentaho 数据集成多选参数
- deep-learning - 将cntk模型v1转换为cntk模型v2
- c++ - 如何在 QTextEdit 小部件的 QString 中包含的 HTML 中编写“<”
- json - 如何在 jsonpath 中获取条件
- java - 如何将 CSVRecord 转换为 List?
- bootstrap-4 - Bootstrap 表格间距和样式