是否可以将一些查询字符串重写为 HTTPS 并将其他所有内容保留在 HTTP 上?

Mat*_*att 3 mod-rewrite rewrite httpd.conf apache-2.2

我正在将查询字符串重写为漂亮的 URI,例如:index.php?q=/en/contact变成/en/contact并且一切正常..

# httpd.conf

# HANDLE THE QUERY
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)

甚至可以重写单个查询来强制https和强制其他所有内容http吗?我尝试了许多不同的方法,这些方法通常以无限循环结束。我可以编写一个插件来在 PHP 中执行此操作,但认为在服务器 conf 中处理此问题会更有效。我很乐意提供任何建议。

编辑: 为了澄清,我希望能够将非 SSL 重写为http://example.com/index.php?q=/en/contact启用的 SSLhttps://example.com/en/contact以及每个未/en/contact写入的查询http://example.com/...

jni*_*zjo 5

htaccess 示例:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^en/contact$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTPS} =on
RewriteRule !^en/contact$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)

http://domain/en/contact重定向以https://domain/en/contact重写 index.php?q=en/contact

http://domain/en/fo 重写为 index.php?q=en/fo

https://domain/en/fo重定向以http://domain/en/fo重写 index.php?q=en/fo

https://domain/en/contact 重写为 index.php?q=en/contact