我如何将整个路径重定向到HTTPS?
问题描述:
我已经搜索过,但还没有找到答案。我如何将整个路径重定向到HTTPS?
我有食谱网站,所有配方路径是这样的:
http://example.com/recipe/recipe-name
我如何可以重定向这整个路径HTTPS?
现在我只有重定向到我的主页,这是工作正常。
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
谢谢。
答
RewriteCond %{HTTP_HOST} ^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule^https://%1%{REQUEST_URI} [NE,L,R=301]
上述用于非HTTPS代码& WWW重定向==> HTTPS加www