首页 > 解决方案 > 重定向到 HTTPS,除了一系列 URL

问题描述

我需要在一系列网址上推迟 https ......

现在我得到了这个: https ://sub.domain.com/release/download/ {id}

我需要将所有 /release/download/{id} url 重定向到 http

我从这里尝试了几种解决方案: Mod_rewrite http->https 重定向除了一个 URL

但没有一个工作。

我在我的 apache conf 中得到了这个:

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

标签: apache.htaccesshttpsapache2

解决方案


您可以使用以下 RewriteRule

RewriteEngine On
#redirect http to https except "/release/download/*
RewriteCond %{REQUEST_URI} !^/release/download/.*
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

推荐阅读