.htaccess - 将 *example.com/* 重定向到 https ://example. com/*

标签 .htaccess mod-rewrite redirect ssl https

我的 SSL 证书在我的 URL 前面没有“www”,当用户从 http 切换到 https 时,我遇到了 Javascript 的同源策略问题。

我想知道如何(在 .htaccess 中输入什么?)重定向所有内容(http://www.example.com、http://example.com 和 https://www。 example.com) 到 https://example.com

此外,我希望在我的 URL (*example.com/*) 之后输入任何内容 在键入的 URL 之前也使用 https 重定向。 (https://example.com/[输入的内容])。

谢谢!

最佳答案

将此代码放入您的 DOCUMENT_ROOT/.htaccess 文件中:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [NE,R=301,L]

关于.htaccess - 将 *example.com/* 重定向到 https ://example. com/*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24192988/

相关文章:

根据用户的位置将用户重定向到最近的服务器,而无需更改 url

django 如何从模板中重定向到主页

php - 当我将 URL 作为参数传递时 Apache 失败

.htaccess - 如何使用 .htaccess 为多个参数创建干净的 url

php - 使用 .htaccess 在目录(包括所有子目录)中禁用 PHP

.htaccess 无需重定向重写多个 url

apache - 如何使基本身份验证排除重写的 URL

c# - 如何正确重定向 StdIn/StdOut 来控制 VLC?

.htaccess - 重定向到 https ://www. example.com

.htaccess - htaccess 将所有流量重定向到 http(非 ssl)