Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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
.htaccess Htaccess和从https页面重定向到非https页面_.htaccess_Http_Mod Rewrite_Redirect_Https - Fatal编程技术网

.htaccess Htaccess和从https页面重定向到非https页面

.htaccess Htaccess和从https页面重定向到非https页面,.htaccess,http,mod-rewrite,redirect,https,.htaccess,Http,Mod Rewrite,Redirect,Https,我有一个网站,所有的URL都被重写,以避免看到扩展名和原始文件名。因此,在我的htaccess中,我有以下内容: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^example-1$ filename_1.php RewriteRule ^example-2$ filename_2.php 现在,我也有一些页面,我只想成为https和http。所以,假设我希望filename_1始终为https,filename_2始终为http。所以,我有以

我有一个网站,所有的URL都被重写,以避免看到扩展名和原始文件名。因此,在我的htaccess中,我有以下内容:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^example-1$ filename_1.php
RewriteRule ^example-2$ filename_2.php
现在,我也有一些页面,我只想成为https和http。所以,假设我希望filename_1始终为https,filename_2始终为http。所以,我有以下代码

RewriteCond %{HTTPS} off
RewriteRule ^(filename_1)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R]

这只是一个简单的例子,但实际上我有很多文件受这两条规则的影响

现在,我认为它工作得很好,直到我注意到当我在https页面上访问非https页面时,url会改变以显示实际的文件名。因此,如果我打开并尝试访问示例2,url将改为而不是。从http到https也是如此。在这些例子中我保持简单,但问题只出现在url中带有变量的页面上。像www.mywebpage.com/homepage这样简单的网站很好用

因此,我添加了这行代码:

    RewriteCond %{HTTPS} on 
    RewriteCond %{REQUEST_URI} !^/(example-2)/ [NC]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301,NE]
所以,从https到http是可行的,但后来事情变得疯狂了!我在某些https和非https页面上得到重定向循环,我不知道为什么!问题是,我从一次添加一个页面到这个新规则开始。我甚至还没有添加的页面给了我一些重定向循环。然后我尝试添加这些页面,但我没有打开https,而是关闭了https,这变得更加疯狂

因此,我的问题是,让以下各项和谐地发挥作用的好方法是什么: 1.将所有URL重写为自定义URL 2.拥有http和https页面,同时保留自定义URL并避免所有重定向循环


谢谢

你能出示你的完整的.htaccess吗?我只有一堆文件名。我用:RewriteEngine启动htaccess并用关闭它,但其他所有内容都是使用我上面编写的规则的一堆文件名。除了https/http转换之外,它工作得很好。不查看所有代码就很难进行调查/提出建议。如果它太大,你可以把它放在粘贴箱上,并在这里提供链接。
    RewriteCond %{HTTPS} on 
    RewriteCond %{REQUEST_URI} !^/(example-2)/ [NC]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301,NE]