简体   繁体   English

如何使用 .htaccess 将所有页面重定向到 https,但有例外?

[英]How can I redirect all pages to https, using .htaccess, with exceptions?

I have used htaccess to force all pages to re route to https using...我已经使用 htaccess 强制所有页面重新路由到 https 使用...

RewriteEngine on
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://ourdomain.com/$1 [R,L]

Is there any way I can reverse that rule for ourdomain.com/videos && ourdomain.com/blog making sure that these pages are forced to drop the https and use http?有什么办法可以为 ourdomain.com/videos && ourdomain.com/blog 反转这条规则,确保这些页面被迫放弃 https 并使用 http?

You're already part way there with your use of RewriteCond to restrict the rewrites to requests on port 80.您已经使用RewriteCond将重写限制为端口 80 上的请求。

You do not want to rewrite requests on port 80 for /videos and /blog , so:不想改写端口80上的请求/videos/blog ,那么:

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/videos
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^(.*)$ https://ourdomain.com/$1 [R,L]

And you want to rewrite requests for these URLs on port (presumably) 443:并且您想在端口(大概)443 上重写对这些 URL 的请求:

RewriteCond %{SERVER_PORT} 443
RewriteRule ^/((videos|blog)/.*) http://ourdomain.com/$1 [R,L]

Try尝试

RewriteEngine on
RewriteBase /

RewriteCond %{SERVER_PORT} 443
RewriteRule ^blog/?(.*) http://ourdomain.com/blog/$1 [R,L]

RewriteCond %{SERVER_PORT} 443
RewriteRule ^videos/?(.*) http://ourdomain.com/videos/$1 [R,L]

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/videos
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^(.*)$ https://ourdomain.com/$1 [R,L]

one more solution.另一种解决方案。 I hope it may help.我希望它会有所帮助。

RewriteEngine on
Rewritebase /


RewriteCond %{SERVER_PORT} !^443$ [OR]
RewriteCond %{HTTPS} =off [OR]
RewriteCond %{ENV:HTTPS} =off
RewriteRule ^(/(.*))?$ https://%{HTTP_HOST}/$1 [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用带有子域的htaccess和Wordpress将所有页面重定向到“ https”? - How redirect all pages to 'https' using htaccess and Wordpress with a subdomain? htaccess重定向到https的所有页面,除了一个 - htaccess redirect to https all pages except one 如何使用htaccess将所有未找到的页面重定向到公共页面 - how to redirect all the not found pages in to a common page using htaccess 如何使用htaccess重定向不同的多个页面 - how to redirect different Multiple pages using htaccess 我如何使用 .htaccess 重定向像 (https://example.com/digital-marketing.php/ercbierubcrei) 这样的非结构化链接? - How can i redirect unstructured link like (https://example.com/digital-marketing.php/ercbierubcrei) using .htaccess? 如何重定向所有现有的.php 文件,但 .htaccess 中的例外情况 - How to redirect all existing .php files with exceptions in .htaccess 如何编写.htaccess重定向以查找所有号码? - How can I write a .htaccess redirect to find all numbers? 使用htaccess将所有子域从HTTP重定向到HTTPS - Redirect all subdomains from HTTP to HTTPS using htaccess 如何使用.htaccess将所有内容重定向到https,www和index.php? - How do I redirect all to https, www & index.php with .htaccess? 如何使用.htaccess规则将所有传入的HTTP URL重定向到WordPress中的https - How to Redirect all incoming http urls to https in WordPress using .htaccess rule
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM