Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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://www 和到站点的根页面_.htaccess - Fatal编程技术网

.htaccess htaccess重定向到https://www 和到站点的根页面

.htaccess htaccess重定向到https://www 和到站点的根页面,.htaccess,.htaccess,我试图修改我的ht访问文件,通过https站点而不是旧站点重定向对站点的访问 下面ht代码的第一段是访问代码中仅允许通过根文件页进行访问的部分。该部分工作正常 然而,第二部分是将所有内容重新定向到HTTPS站点并阻止访问http站点的部分。这不起作用,仍然可以通过http访问该站点 RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond

我试图修改我的ht访问文件,通过https站点而不是旧站点重定向对站点的访问

下面ht代码的第一段是访问代码中仅允许通过根文件页进行访问的部分。该部分工作正常

然而,第二部分是将所有内容重新定向到HTTPS站点并阻止访问http站点的部分。这不起作用,仍然可以通过http访问该站点

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]


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

#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
对于如何修改代码,我非常感谢您的建议。

尝试从重写规则中删除L。一旦满足规则,它将停止处理,因此它将始终停止

改变这个

RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

看看这对你有什么好处

编辑:

如果您只想将所有流量和非https定向到https和索引页,下面的代码也会执行相同的操作。注意,我使用了域名。用真实的站点替换yoursite.com。看看这是怎么回事

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*)$ https://www.yoursite.com/ [R=301,L]

RewriteCond %{REQUEST_URI} !/$ 
RewriteCond %{REQUEST_URI} !/index.php
RewriteRule ^(.*)$ / [NC,R=301,L]

嘿,巴拿马。非常感谢你的回答。我现在就试试。但是,如果我删除[L],它仍然只允许通过根主页访问该站点。我的意思是,我不希望用户能够通过根索引pag访问站点accept。我试过了。它不阻止通过http进入索引页。但是,一旦我尝试导航到另一个页面,它就会将其发送到HTTPS。如何防止进入主页http?您到底想实现什么?如果您只是想将所有页面重定向到root或index.php并使用https,那么这并不难。对我已经将用户重定向到根目录。i、 e《守则》第一段。但是我现在需要另外将它们定向到HTTPS索引页面。因此,所有访问都必须通过根主页
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*)$ https://www.yoursite.com/ [R=301,L]

RewriteCond %{REQUEST_URI} !/$ 
RewriteCond %{REQUEST_URI} !/index.php
RewriteRule ^(.*)$ / [NC,R=301,L]