使用.htaccess强制只通过SSL打开一个HTML页面

时间:2015-03-13 13:21:07

标签: .htaccess https

我想强制所有客户端使用SSL访问我网站上的HTML文件。我的根文件夹中为snipprintslive.htmlwww.stellamays.co.uk/sniprintslive.html

我试过了:

RewriteEngine On
#https
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^sniprintslive https://stellamays.co.uk/sniprintslive [R=301,L]

这适用于网站的其余部分,但访问sniprintslive.html会出现“找不到文件”错误。

我尝试将页面放在子文件夹中(相对链接的噩梦,但是嘿嘿)并将.htaccess文件放在同一个文件夹中。

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} printsfolder/sniprintslive.html
RewriteRule ^(.*)$ https://www.stellamays.co.uk/printsfolder/sniprintslive.html$1 [R,L]

我再次收到同样的错误。

我不理解这种编程语言,但想知道是wwwhttp:这些令人不安的东西。

请注意,我的服务器将使用.htaccess,因为我使用类似的代码成功强制整个网站使用HTTPS打开。

1 个答案:

答案 0 :(得分:0)

修复它...我有点害怕代码cos我没有把我的网站放在???! 但它很有效地工作了

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