强制非https版本的网站

时间:2017-12-13 20:37:47

标签: apache .htaccess mod-rewrite

安装ssl并使用htaccess进行所有页面https后,我意识到我的网站实际上无法运行https,因为它有很多带有http协议的嵌入代码,无法更改为https或删除,只是删除了重写规则哪个强制https不起作用,因为谷歌已经使用https索引所有页面,所以现在大部分谷歌搜索流量都转到https版网站,他们看到混合内容错误。 我尝试实现我在论坛中找到的示例,但是当我应用此代码时

RewriteCond %{HTTPS} on [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

浏览器始终从https://example.com/anypage重定向到http://example.com/index.php

以下是.htaccess文件的完整代码

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

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

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

#Force non-www:
RewriteCond %{HTTP_HOST} ^www\.example\.com[NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

RewriteCond %{HTTPS} on [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>

0 个答案:

没有答案