modRewrite RewriteCond可关闭特定请求URL的ssl重定向


modRewrite RewriteCond to turn off ssl redirect for a certain requested URL

在我的网站mycreditstatus.co.za中,我使用.htaccess重写URL并将其从http重定向到https,以下是我在public_html(http)目录中使用的.htacccess代码:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

它工作得很好,但它将所有http URL重写并重定向到https。

问题是,我的网站也对非https网站执行一些请求,所以我不想重写和重定向一些链接到https。

以下是我不想重定向/重写的链接之一:

http://imupost.co.za/

我想知道应该为public_ssl(https)目录上的.htaccess编写的代码,因为请求将来自那里。

试试这个代码:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^imupost.co.za$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

在您的public_html dir:下的.htaccess中保存此代码

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^imupost'.co'.za$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

并将此代码放在.htaccess中的public_ssl目录下:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^imupost'.co'.za$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]