htaccess 将 4 个特定页面重定向到 https [英] htaccess redirect 4 specific pages to https

查看:22
本文介绍了htaccess 将 4 个特定页面重定向到 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a problem where I need to redirect 4 specific pages on my website to their https secure versions.

我目前有一个 htaccess 文件,它将 example.comwww.example.com 重定向到 https://example.com>

I currently have an htaccess file which is redirecting both example.com and www.example.com to https://example.com

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

我需要的是这样的

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] 

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

Notice that I have removed the third RewriteCond line from the above code as I don't want every page on my website to be displaying https only the pages I specifically state.

我该如何解决这个问题?

How can I resolve this problem?

另外,这条线是否涵盖 www.example.com 和 example.com?

PS also, is this line covering both www.example.com and example.com?

RewriteCond %{HTTP_HOST} ^(.*.)*example.com$ [NC]

我假设

^(.*.)*

有什么关系吗?

推荐答案

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]

这篇关于htaccess 将 4 个特定页面重定向到 https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆