gpt4 book ai didi

apache - 如何重写所有不包含短语的非 ssl 请求?

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:21 24 4
gpt4 key购买 nike

我有一个特殊的问题。我需要重写所有转到 http => https 的请求,另外,如果 url 缺少 www,我想修复它,因此我也有一个重写规则。

现在,有一个异常(exception),不应该被重写。如果请求是为了 http://www.mydomain.com/ api2/.../..

api2下的一切都不应该重写为https...

这是我当前的 .htaccess :

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
# Start A2 Switcher Block
# Do not remove or modify this block! Added by PHP Switcher from cPanel to use an alterna$
<IfModule mod_suphp.c>
AddHandler application/x-httpd-php-5.4.13 .php
</IfModule>
# End A2 Switcher Block

有人能帮忙吗?

最佳答案

让你的代码像这样:

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule !^api2/ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]

RewriteCond %{HTTPS} off
RewriteRule !^api2/ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]

RewriteCond %{HTTPS} on
RewriteRule ^api2/ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^api2/ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]

# Start A2 Switcher Block
# Do not remove or modify this block! Added by PHP Switcher from cPanel to use an alterna$
<IfModule mod_suphp.c>
AddHandler application/x-httpd-php-5.4.13 .php
</IfModule>
# End A2 Switcher Block

关于apache - 如何重写所有不包含短语的非 ssl 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23729283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com