简体   繁体   English

modRewrite RewriteCond可以为某个请求的URL关闭ssl重定向

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

In my website mycreditstatus.co.za, I use .htaccess to rewrite and redirect a URL from http to https and here's the code I use for the .htaccess in the public_html (http) directory: 在我的网站mycreditstatus.co.za中,我使用.htaccess重写URL并将其从http重定向到https,这是我在public_html(http)目录中用于.htaccess的代码:

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

It works just fine but it rewrites and redirects all http urls into https. 它工作得很好,但是它将所有http URL重写并将其重定向到https。

The problem is that my website also performs some requests to non-https sites so I don't want to rewrite and redirect some of the links to https. 问题是我的网站还向非https网站执行了一些请求,因此我不想重写某些链接并将其重定向到https。

Here's one of the links that I don't want to redirect/rewrite: 这是我不想重定向/重写的链接之一:

http://imupost.co.za/ http://imupost.co.za/

I want to know the code that I should write for the .htaccess on the public_ssl (https) directory since the request will be coming from there. 我想知道应该为public_ssl(https)目录上的.htaccess编写的代码,因为请求将来自那里。

Try this code : 试试这个代码:

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

Have this code in .htaccess under your public_html dir: 在您的public_html目录下的.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]

And have this code in .htaccess under your public_ssl dir: 并将此代码放在您的public_ssl目录下的.htaccess中:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM