htaccess将4个特定页面重定向到https

dan*_*the 7 .htaccess mod-rewrite redirect url-rewriting

我有一个问题,我需要将我网站上的4个特定页面重定向到他们的https安全版本.

我现在有这两个重定向一个htaccess文件example.com,并www.example.comhttps://example.com

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*\.)*example.com$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://example.com/$1 [R] 
Run Code Online (Sandbox Code Playgroud)

我需要的是类似的东西

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*\.)*example.com/page1.php$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)*example.com/page2.php$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)*example.com/page3.php$ [NC]
RewriteCond %{HTTP_HOST} ^(.*\.)*example.com/page4.php$ [NC]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://example.com/page1.php$1 [R] 
RewriteRule ^(.*)$ https://example.com/page2.php$1 [R] 
RewriteRule ^(.*)$ https://example.com/page3.php$1 [R] 
RewriteRule ^(.*)$ https://example.com/page4.php$1 [R] 
Run Code Online (Sandbox Code Playgroud)

请注意,我已从上面的代码中删除了第三个RewriteCond行,因为我不希望我网站上的每个页面只显示https,只显示我明确说明的页面.

我该如何解决这个问题?

PS也是,这一行涵盖www.example.com和example.com?

RewriteCond %{HTTP_HOST} ^(.*\.)*example.com$ [NC]
Run Code Online (Sandbox Code Playgroud)

我在假设

^(.*\.)*
Run Code Online (Sandbox Code Playgroud)

有什么用呢?

Ger*_*ben 12

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

#redirect www.mydomain.com to mydomain.com (or any other subdomain)
RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]

#force https for certain pages    
RewriteCond %{HTTPS} !=on
RewriteRule ^(page1\.php|page2\.php|page3\.php|page4\.php)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
Run Code Online (Sandbox Code Playgroud)