{"id":771,"date":"2020-06-11T12:21:07","date_gmt":"2020-06-11T19:21:07","guid":{"rendered":"https:\/\/SUMMALAI.COM\/?p=771"},"modified":"2020-06-13T23:39:17","modified_gmt":"2020-06-14T06:39:17","slug":"redirect-request-from-http-to-https-apache","status":"publish","type":"post","link":"https:\/\/SUMMALAI.COM\/?p=771","title":{"rendered":"Redirect Request from HTTP to HTTPS (Apache)"},"content":{"rendered":"\n<p>original: <a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/HTTPD\/RedirectSSL\">https:\/\/cwiki.apache.org\/confluence\/display\/HTTPD\/RedirectSSL<\/a><\/p>\n\n\n\n<p>Let&#8217;s say you want&nbsp;http:\/\/www.example.com\/secure\/&nbsp;to always be sent over SSL (I presume here that both the normal and the SSL vhost have the same content). You could do this by linking to the correct page from within your HTML pages&#8230; but there will always be some user who will sneak by it that way.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/HTTPD\/RedirectSSL#RedirectSSL-RedirectRequesttoSSL\">Redirect Request to SSL<\/a><ul><li><a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/HTTPD\/RedirectSSL#RedirectSSL-Usingvirtualhosts(usingredirect)\">Using virtual hosts (using redirect)<\/a><\/li><li><a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/HTTPD\/RedirectSSL#RedirectSSL-Using.htaccessfilesandredirect\">Using .htaccess files and redirect<\/a><\/li><li><a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/HTTPD\/RedirectSSL#RedirectSSL-Usingmod_rewrite\">Using mod_rewrite<\/a><\/li><\/ul><\/li><\/ul>\n\n\n\n<p><strong>Using virtual hosts (using redirect)<\/strong><\/p>\n\n\n\n<p>When using SSL, you will frequently have at least two virtual hosts: one on port 80 to serve ordinary requests, and one on port 443 to serve SSL. If you wish to redirect users from the non-secure site to the SSL site, you can use an ordinary&nbsp;<a href=\"http:\/\/httpd.apache.org\/docs\/trunk\/mod\/mod_alias.html#redirect\">Redirect<\/a>&nbsp;directive inside the non-secure&nbsp;<a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/HTTPD\/RedirectSSL\">VirtualHost<\/a>:<\/p>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;The&nbsp;NameVirtualHost&nbsp;directive only applies to the 2.2.x releases of httpd.<\/p>\n\n\n\n<p>NameVirtualHost *:80<\/p>\n\n\n\n<p>&lt;VirtualHost *:80&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp; ServerName mysite.example.com<\/p>\n\n\n\n<p>&nbsp;&nbsp; DocumentRoot \/usr\/local\/apache2\/htdocs<\/p>\n\n\n\n<p>&nbsp;&nbsp; Redirect \/secure https:\/\/mysite.example.com\/secure<\/p>\n\n\n\n<p>&lt;\/VirtualHost&gt;<\/p>\n\n\n\n<p>&lt;VirtualHost _default_:443&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp; ServerName mysite.example.com<\/p>\n\n\n\n<p>&nbsp;&nbsp; DocumentRoot \/usr\/local\/apache2\/htdocs<\/p>\n\n\n\n<p>&nbsp;&nbsp; SSLEngine On<\/p>\n\n\n\n<p># etc&#8230;<\/p>\n\n\n\n<p>&lt;\/VirtualHost&gt;<\/p>\n\n\n\n<p>When redirecting everything you don&#8217;t even need a DocumentRoot:<\/p>\n\n\n\n<p>NameVirtualHost *:80<\/p>\n\n\n\n<p>&lt;VirtualHost *:80&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp; ServerName www.example.com<\/p>\n\n\n\n<p>&nbsp;&nbsp; Redirect \/ https:\/\/secure.example.com\/<\/p>\n\n\n\n<p>&lt;\/VirtualHost&gt;<\/p>\n\n\n\n<p>&lt;VirtualHost _default_:443&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp; ServerName secure.example.com<\/p>\n\n\n\n<p>&nbsp;&nbsp; DocumentRoot \/usr\/local\/apache2\/htdocs<\/p>\n\n\n\n<p>&nbsp;&nbsp; SSLEngine On<\/p>\n\n\n\n<p># etc&#8230;<\/p>\n\n\n\n<p>&lt;\/VirtualHost&gt;<\/p>\n\n\n\n<p><strong>Note:<\/strong>&nbsp;Once the configuration is working as intended, a permanent redirection can be considered. This avoids caching issues by most browsers while testing. The directive would then become:<\/p>\n\n\n\n<p>&nbsp;&nbsp; Redirect permanent \/ https:\/\/secure.example.com\/<\/p>\n\n\n\n<p><strong>Using .htaccess files and redirect<\/strong><\/p>\n\n\n\n<p>Redirect can also be used inside .htaccess files or to address particular URLs, as in:<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<p>&nbsp;&nbsp; Redirect \/login https:\/\/mysite.example.com\/login<\/p>\n\n\n\n<p><strong>Using mod_rewrite<\/strong><\/p>\n\n\n\n<p>While the&nbsp;&lt;VirtualHost&gt;&nbsp;the solution is recommended because it is simpler and safer, you can also use mod_rewrite to get the same effect as described here:&nbsp;<a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/HTTPD\/RewriteHTTPToHTTPS\">RewriteHTTPToHTTPS<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>original: https:\/\/cwiki.apache.org\/confluence\/display\/HTTPD\/RedirectSSL Let&#8217;s say you want&nbsp;http:\/\/www.example.com\/secure\/&nbsp;to always be sent over SSL (I presume here that both the normal and the SSL vhost have the same content). You could do this by linking to the correct page from within your HTML pages&#8230; but there will always be some user who will sneak by it that way. <a class=\"read-more\" href=\"https:\/\/SUMMALAI.COM\/?p=771\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[104,5],"tags":[106,105],"class_list":["post-771","post","type-post","status-publish","format-standard","hentry","category-apache","category-linux","tag-https","tag-redirect"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=771"}],"version-history":[{"count":0,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=\/wp\/v2\/posts\/771\/revisions"}],"wp:attachment":[{"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/SUMMALAI.COM\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}