http - 将几页的 http 重写为 https

标签 http .htaccess mod-rewrite https

我看到这里有类似的东西
How to force rewrite to HTTPS except for a few pages in Apache?
因此,如果有人能帮助我做相反的事情,我将非常感激。
我需要重写所有请求
http://www.default.com
所以我这样做了:

Options FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^default.com
RewriteRule (.*) http://www.default.com/ [R=301,L]

现在我需要对某些网址强制使用 https 协议(protocol),例如:
<a href="http://www.default.com/user/loginUser" rel="noreferrer noopener nofollow">http://www.default.com/user/loginUser</a>
ETC。
我真的不知道。今天我已经为此奋斗了几个小时,最接近的是一些无限循环的重定向:P

另一件事是,在 CMS (由其他人编写)所在的子文件夹中,还有另一个带有一些重写规则的 .htaccess 文件,我不知道这是否会影响我想要做的事情。

如果您有任何建议,我将不胜感激。

最佳答案

对于每个网址,您需要执行以下操作:

RewriteCond %{HTTPS} off
RewriteRule ^user/loginUser(.*)$ https://www.default.com/user/LoginUser$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteRule ^another/url(.*)$ https://www.default.com/another/url$1 [R=301,L]

等等

关于http - 将几页的 http 重写为 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11550459/

相关文章:

javascript - 在进行缓存的 Ajax 调用时如何避免竞争条件

ruby-on-rails - 使用 Ruby Controller 读取 Instagram JSON 并使用 HTTParty gem 传递到 View

php - 使用 .htaccess 永久重定向到子文件夹

php - .htaccess 重写规则在 Mac 上无法正常工作

php - 重写后无法访问 $_GET

spring - 获取请求 header 名称和值

javascript - 在 angularJs 中处理资源和图像超时

php - 删除文件扩展名时出现 404 错误在 wamp 上有效但在 lamp 上无效

laravel - 更改 laravel 的 htaccess,使其路由到特定文件

.htaccess - 对于使用 .htaccess 输入的任何 URL,强制 SSL 到 www 子域?