本文介绍了使用“mod_rewrite的”我怎么强制HTTPS某些路径和HTTP为所有其他人呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用的mod_rewrite 清洁URL的PHP​​,Apache的应用程序。我有很多touble的让某些页面和路径被迫HTTPS,同时确保所有其它仍将作为HTTP。

I have a PHP-Apache application using mod_rewrite for clean URLs. I am having a lot of touble getting certain pages and paths forced to HTTPS while also ensuring all others will remain as HTTP.

下面是我的意思的例子:

Here is an example of what I mean:

// http://www.example.com/panel/ -> Should always redirect to HTTPS
// http://www.example.com/store/ -> Should always redirect to HTTPS

// Anything not in the above should always be HTTP
// so...
// https://www.example.com/not-in-above-rules -> Should always redirect to HTTP

任何想法?

推荐答案

您可以把这样的事情在你的:80虚拟主机:

You can put something like this in your :80 vhost:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(panel/|store/payment) https://%{HTTP_HOST}%{REQUEST_URI}

这在您的:443虚拟主机:

And this in your :443 vhost:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule !^(panel/|store/payment) http://%{HTTP_HOST}%{REQUEST_URI}

这篇关于使用“mod_rewrite的”我怎么强制HTTPS某些路径和HTTP为所有其他人呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 07:39