htaccess的301重定向所有的https到http除一PAGE [英] .htaccess 301 redirect for all https to http EXCEPT ONE PAGE

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

问题描述

下面是code我目前在我的.htaccess文件:

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{HTTP_HOST} ^ example.com [NC]
重写规则^(。*)$ http://www.example.com/$1 [L,R = 301]

RewriteEngine叙述上
的RewriteCond%{} HTTPS上
(。*)重写规则的http:// {%HTTP_HOST}%{REQUEST_URI} [L,R = 301]
 

我知道杰克有关重写......而所有关于这个问题的其他职位真的不适合我的标准,我不知道有足够的了解,试图破译它的语言。

基本上,我需要的是这样的:

  1. 重定向的所有实例example.com到www.example.com
  2. 重定向 HTTPS // www.example.com到 HTTP ://www.example.com的所有实例的除外第1页的!!!! (如果它的事项,该页面的文件名是payments.php)

在code我有以上的作品,但对于第1页,我需要为HTTPS,它重写URL为http。那一页已经为HTTPS。

谢谢, 克里斯

解决方案
  

的Apache / 2.2.6(Win32的)了mod_ssl / 2.2.8的OpenSSL / 0.9.8g PHP / 5.2.6

我在本地测试过,所有的用例似乎很好地工作。如果您还有其他问题,请随时问。

 #重写example.com的规则
RewriteEngine叙述上
的RewriteBase /

#从example.com重定向到www.example.com
的RewriteCond%{HTTP_HOST} ^例如\ .COM [NC]
(。*)重写规则^ $ HTTP://www.% {HTTP_HOST} / $ 1 [R = 301,L]

#启用SSL上的付款
的RewriteCond%{} HTTPS关闭
的RewriteCond%{SCRIPT_FILENAME} \ /金\ .PHP [NC]
(。*)重写规则^ $的https://%{HTTP_HOST} / $ 1 [R = 301,L]

#打开SSL关闭一切,但付款
的RewriteCond%{} HTTPS上
的RewriteCond%{} SCRIPT_FILENAME!\ /金\ .PHP [NC]
(。*)重写规则^ $的http://%{HTTP_HOST} / $ 1 [R = 301,L]
 

重要!当用户从任何的 HTTPS 的配页的 WWW 的任何的 HTTPS 的页面导航没有 WWW 的,他要求接受你的非www域名的安全证书。

例如(YES =请求接受证书,NO - 对面):

  1)https://www.asdf.com/payments.php  -  YES(www.asdf.com)
2)http://www.asdf.com/phpinfo.php  -  NO
3)https://asdf.com/phpinfo.php  -  YES(asdf.com)
4)https://www.asdf.com/phpinfo.php  -  NO
 

我试图重新排序规则的.htaccess没有成功。如果有人找到一个更好的解决方案,这将是非常美联社preciated。

Here is the code I have currently in my .htaccess file:

Options +FollowSymLinks 
RewriteEngine on
RewriteBase / 
RewriteCond %{HTTP_HOST} ^example.com [NC] 
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I know jack about rewrites...and all of the other posts on this subject really don't fit my criteria and I don't know enough about the language to try and decipher it.

Basically what I need is this:

  1. redirect all instances of "example.com" to "www.example.com"
  2. redirect all instances of "https//www.example.com" to "http://www.example.com" with the exception of 1 page!!!! (in case it matters, the filename of that page is payments.php)

The code I have above works, but for the 1 page that I need to be https, it is rewriting the url to http. That one page has to be https.

Thanks, Chris

解决方案

Apache/2.2.6 (Win32) mod_ssl/2.2.8 OpenSSL/0.9.8g PHP/5.2.6

I've tested it locally, all use cases seem to work fine. If you have further questions, feel free to ask.

# Rewrite Rules for example.com
RewriteEngine On
RewriteBase /

# Redirect from example.com to www.example.com
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Turn SSL on for payments
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/payments\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Turn SSL off everything but payments
RewriteCond %{HTTPS} on
RewriteCond %{SCRIPT_FILENAME} !\/payments\.php [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

IMPORTANT! When the user navigates from any https page with www to any https page without www, he's asked to accept security certificate of your non-www domain.

For example (YES = request to accept the certificate, NO - opposite):

1) https://www.asdf.com/payments.php - YES (www.asdf.com)
2) http://www.asdf.com/phpinfo.php - NO
3) https://asdf.com/phpinfo.php - YES (asdf.com)
4) https://www.asdf.com/phpinfo.php - NO

I tried to reorder rules in .htaccess with no success. If anyone finds a better solution, it'll be highly appreciated.

这篇关于htaccess的301重定向所有的https到http除一PAGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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