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

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

问题描述

我有一个问题,我需要重定向4在我的网站的特定页面,以自己的HTTPS安全版本。

我现在有这两个重定向 mydomain.com www.mydomain.com 来一个htaccess文件 https://mydomain.com

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^(。* \。)* mydomain.com $ [NC]
的RewriteCond%{} SERVER_PORT!^ 443 $
重写规则^(。*)$ https://mydomain.com/$1 [R]
 

我需要的是像

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^(。* \。)* mydomain.com/page1.php$ [NC]
的RewriteCond%{HTTP_HOST} ^(。* \。)* mydomain.com/page2.php$ [NC]
的RewriteCond%{HTTP_HOST} ^(。* \。)* mydomain.com/page3.php$ [NC]
的RewriteCond%{HTTP_HOST} ^(。* \。)* mydomain.com/page4.php$ [NC]
的RewriteCond%{} SERVER_PORT!^ 443 $
重写规则^(。*)$ https://mydomain.com/page1.php$1 [R]
重写规则^(。*)$ https://mydomain.com/page2.php$1 [R]
重写规则^(。*)$ https://mydomain.com/page3.php$1 [R]
重写规则^(。*)$ https://mydomain.com/page4.php$1 [R]
 

请注意,我已删除从上面的code中的第三行的RewriteCond,因为我不希望在我的网站的每个页面要显示仅HTTPS网页我特地状态。

可能有人请帮我解决这个问题呢?

在此先感谢。


PS也就是这条线涵盖www.mydomain.com和mydomain.com?

 的RewriteCond%{HTTP_HOST} ^(。* \。)* mydomain.com $ [NC]
 

我假设

  ^(。* \。)*
 

有什么关系呢?

解决方案

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteBase /

#REDIRECT www.mydomain.com到mydomain.com(或任何其他子域)
的RewriteCond%{HTTP_HOST}!^ mydomain.com $ [NC]
重写规则^(。*)$ http://mydomain.com/$1 [L,R = 301]

#force HTTPS的特定页面
的RewriteCond%{} HTTPS!=上
重写规则^(第1页\ .PHP |第2页\ .PHP |第3页\ .PHP |第4页\ .PHP)$的https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
 

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

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

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

what I need is something like

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

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.

Could someone please help me resolve this problem?

Thanks in advance.


p.s also, is this line covering both www.mydomain.com and mydomain.com?

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

I'm assuming that

^(.*\.)*

has something do with it?

解决方案

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天全站免登陆