Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从my.htaccess文件中的HTTPS中删除单个链接_.htaccess_Mod Rewrite_Https_Url Rewriting - Fatal编程技术网

从my.htaccess文件中的HTTPS中删除单个链接

从my.htaccess文件中的HTTPS中删除单个链接,.htaccess,mod-rewrite,https,url-rewriting,.htaccess,Mod Rewrite,Https,Url Rewriting,我正在强制整个站点通过HTTPS运行。然后,我在.htaccess文件中通过index.php强制执行www并处理页面 <IfModule mod_rewrite.c> Options +FollowSymlinks RewriteEngine On RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"' [OR] RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ - [env=p

我正在强制整个站点通过
HTTPS
运行。然后,我在
.htaccess
文件中通过
index.php
强制执行
www
并处理页面

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"' [OR]
  RewriteCond %{HTTPS} !=on
  RewriteRule ^(.*)$ - [env=proto:http]
  RewriteCond %{HTTP:CF-Visitor} '"scheme":"https"' [OR]
  RewriteCond %{HTTPS} =on
  RewriteRule ^(.*)$ - [env=proto:https]
</IfModule>
我还尝试使用以下方法将所有内容放在一个块中:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    #Redirect non-www to www
    RewriteCond %{HTTP_HOST} ^local.com [NC]
    RewriteRule ^(.*)$ http://www.local.com/$1 [L,NC]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

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

    #Redirect singular segments first
    RewriteCond %{QUERY_STRING} ^PRD=([0-9]+) [NC]
    RewriteRule ^(.*)$ http://www.local.com/$1 [L]
</IfModule>

选项+FollowSymlinks
重新启动发动机
#将非www重定向到www
重写cond%{HTTP_HOST}^local.com[NC]
重写规则^(.*)$http://www.local.com/$1[L,NC]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
重写条件%{HTTPS}关闭
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[L]
#首先重定向单数段
RewriteCond%{QUERY_STRING}^PRD=([0-9]+)[NC]
重写规则^(.*)$http://www.local.com/$1[L]

如果要设置https重定向,则必须对查询字符串使用重写条件,请尝试下面的

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

不完全清楚要传递哪个url,请提供示例。已更新op以包含链接示例。整个站点被强制使用https。我想为具有该查询字符串和数值的链接添加例外。您已经显示了两个规则块,但不清楚使用的是哪一个。您是否可以显示您的完整工作.htaccess?这些是
.htaccess
文件中仅有的两个
mod\u rewrite
段。它们按我上面的顺序排列。我试过这个和其他方法,但它陷入了从http到https和Back的重定向循环中。您可能需要重新考虑
^(.*)$
,因为它匹配所有模式,请仅使用^caret进行尝试。谢谢您的帮助。我想我不明白在哪里。我最终使用了
proto
变量,因为CloudFare有时会干扰,有时不会。这似乎抓住了他们所有人。遗憾的是,我对
.htaccess
的熟练程度不如我应该的。我更新了OP以反映我尝试过的几行代码。我想如果我在其他人之前抓到它,它就会重新定向,然后就没事了。但情况似乎并非如此。在看到您的新规则后,我无法看到任何R标志。您的代码没有正确路由主页,从URL中删除
index.php
,因此网站“中断”。它仍然直接转到
https://www.local.com/index.php?PRD=123
:(
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    #Redirect non-www to www
    RewriteCond %{HTTP_HOST} ^local.com [NC]
    RewriteRule ^(.*)$ http://www.local.com/$1 [L,NC]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

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

    #Redirect singular segments first
    RewriteCond %{QUERY_STRING} ^PRD=([0-9]+) [NC]
    RewriteRule ^(.*)$ http://www.local.com/$1 [L]
</IfModule>
RewriteCond %{HTTPS} off
RewriteCond %{QUERY_STRING} !^PRD=(\d+)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]