重定向https .htaccess
问题描述:
嘿,大家所以我最近添加https到一个网站,现在我有一个小问题重定向,如果有人去的网站没有www。重定向https .htaccess
他们去到以下网址
例如:https://www.example.com/https://example.com
,而不是去https://example.com
代码:
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^koenschenk.nl [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]
{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ http://www.koenschenk.nl/$1 [L,R=301,NC]
Redirect 301 https://koenschenk.nl https://www.koenschenk.nl
ErrorDocument 404 /404.php
答
你可以从HTTP设置重定向到HTTPS通过编辑以下代码在您的/etc/apache2/apache2.conf
(假设您使用的是Linux机器):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule/https://{koenschenk.nl}/
将上述代码行放在.htaccess文件中的网站根文件夹中。
我注意到的唯一事情就是你用最后一个'RewriteRule'重新定向到http。当测试301重定向时,我只会使用curl来实现,因为浏览器倾向于积极缓存这些内容。 –