apache - .htaccess url 从 http 重写为 https

标签 apache .htaccess mod-rewrite ssl

我最近刚刚使用 SSL 证书更新了我们的网站。我们正在重写 URL,并在输入 http://example.com 时或 http://www.example.com这被翻译成 https://example.com

但是,我们发现许多访问者的收藏夹链接到特定页面或文件,而 .htaccess 翻译失败。

例如点击收藏的时候 http://example.com/themes/default/images/emailLogo.png 然后访问者被引导到 https://example.comthemes/default/images/emailLogo.png (注意 URL 中缺少的斜杠)

这是我的 .htaccess 文件信息

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{HTTPS} off
RewriteRule ^images/.+$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} !(example\.org|example-me.org|example.me)$
RewriteRule ^(.*)$ https://example.org/$1 [R=302,L]

RewriteRule ^http://example.org/images/(.*) https://example.org/images/$1 [R]
RewriteRule ^http://www.example.org/images/(.*) https://example.org/images/$1 [R]
RewriteRule ^(.+)\.html$ /bootstrap.php?file=$1.html [L,NC,QSA]
RewriteRule ^(.+)\.phtml$ /bootstrap.php?file=$1.html [L,NC,QSA]
</IfModule>

ErrorDocument 404 /404.php

DirectoryIndex index.html index.php

最佳答案

如果其他人无意中看到这篇文章,我就会发现问题所在。 apache 配置中有一个重定向,将所有端口 80 请求重定向到 https://example.com

我将其更改为 https://example.com/

(* 注意尾部的斜杠 *)

关于apache - .htaccess url 从 http 重写为 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23917284/

相关文章:

.htaccess - 如何在目录上强制使用 HTTPS 并强制使用 HTTPS 身份验证

php - 如何在 PHP 中将大写 url 查询字符串重定向为小写

apache - 如何增加 .htaccess 中的 apache 超时指令?

php - 如何根据查询字符串中的匹配使用 SetEnvIf?

php - 从根文件夹中的 htaccess 规则中排除子目录

将 PHP 从 5.3.4 升级到 5.3.22 后,PHP CURL 未加载到 WAMP 中

PHP .htaccess 重写 url

apache - 如何制作 tumblr 风格的个人资料 url

Apache Rewrite url - 删除 .html 并返回 404(如果存在 .html)

php - 如何将 get 字符串转换为 slug?