[英]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.