2013-03-27 147 views
0

我在重定向2个简单的html页面时遇到了一些麻烦。.htaccess将2个http页面重定向到https页面

我需要设置重定向:

  1. HTTP://example.com/Folder1/page1.html到https://example.com/Folder1/page1.html
  2. HTTP://example.com/Folder1/Folder2/page2.html https://example.com/Folder1/Folder2/page2.html

只有这两个页面必须从http重定向到https。任何其他页面都必须可用于http和https。

我试着用这些规则:

RewriteCond %{SERVER_PORT} !=443 
rewriterule ^(Folder1)$ https://%{HTTP_HOST}/$1 [R=301,L] 
RewriteCond %{SERVER_PORT} 1=443 
RewriteCond $1 ^Folder1/Folder2 
rewriterule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 

但只有第二重定向的作品。第一个仍然打开http页面。

任何人都可以帮我写正确的规则吗?

回答

0
RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} ^(/Folder1/(page1\.html|Folder2/page2\.html))$ [NC] 
rewriterule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
+0

此规则是否必须放置在.htaccess中的某个网站的根目录中? 或在folder1 .htaccess中? – user2216001 2013-03-27 15:25:33

+0

我尝试将此规则添加到根目录.htaccess文件中,并且仅适用于Folder2。 也许问题Folder2是Folder1的子文件夹? – user2216001 2013-03-27 15:38:40

+0

最好把它们放在网站根目录下的.htaccess中, 重定向工作正常(我已经在http://htaccess.madewithlove.be/上测试过了),你是否试图将Folder2下的所有html页面重定向到https? – 2013-03-27 17:13:34

相关问题