htaccess将除三页以外的所有页面重定向到https

时间:2015-09-04 14:43:42

标签: apache .htaccess mod-rewrite redirect expressionengine

我知道这听起来像是重复但是我已经尝试了尽可能多的方法,我仍然没有得到这个工作。所以请不要自动将其标记为副本。

我正在尝试将http://www.domian.com的所有网页重定向到https://www.domain.com,但三页除外:/ products / product1,/ products / product2,/ products / product3

我还希望这些页面始终指向http,因为如果https页面通过相对链接链接到它,它自然会有https。

同样在游戏中,这是一个表达式引擎网站,我将从URI中删除index.php。

当前的Htaccess,导致这三个页面仍然是https,即使我去那些页面的Http。

 ### secure .htaccess file
<Files .htaccess>
 order allow,deny
 deny from all
</Files>

### EE 404 page for missing pages
ErrorDocument 404 /index.php/site/404

###Block Access to directories with no index file
Options -Indexes

### Simple 404 for missing files
<FilesMatch "(\.jpe?g|gif|png|bmp|css|js|flv)$">
  ErrorDocument 404 "File Not Found"
</FilesMatch>

### Although highly unlikely, your host may have +FollowSymLinks enabled at the root level, yet disallow its addition in .htaccess; in which case, adding +FollowSymLinks will break your setup (probably a 500 error), so just remove it, and your rules should work fine.
###Options +FollowSymlinks
RewriteEngine On
RewriteBase /

###Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET
RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.+) $1 [R=301,L]

### Add the www
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]


###each option I try I replace in this block as a reference
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !^/products/product3
RewriteCond %{REQUEST_URI} !^/products/product1
RewriteCond %{REQUEST_URI} !^/products/product2
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]

######


RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
###

也试过这个,结果与上面相同:

RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} !^(domain\.com/products/product1|domain\.com/products/product2|domain\.com/products/product2) [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(domain\.com/products/product1|domain\.com/products/product2|domain\.com/products/product2) [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]

单独试一试,看看是否可以导航到http://www.domain.com/products/product1并且至少没有重写,但它仍然会重写为https

RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !/products/product1 [NC,OR]
RewriteCond %{REQUEST_URI} !/products/product2 [NC,OR]
RewriteCond %{REQUEST_URI} !/products/product3 [NC,OR]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]

也尝试了这个,它仍然将这些页面写入https。另外,如果我尝试转到http,它会重写为https并且不会删除index.php

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/products/product3
RewriteCond %{REQUEST_URI} !^/products/product1
RewriteCond %{REQUEST_URI} !^/products/product2
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]

RewriteCond %{SERVER_PORT} 80
RewriteRule ^/products/product3 http://www.domain.com/products/product3 [R=301,QSA,L,NE]
RewriteRule ^/products/product1 http://www.domain.com/products/product1 [R=301,QSA,L,NE]
RewriteRule ^/products/product2 http://www.domain.com/products/product2 [R=301,QSA,L,NE]

我老老实实地试过上述所有这些的10到15个版本但仍然无法得到它。包括添加index.php?如果request_URI在删除之前将其视为request_URI的一部分,则返回到request_URI。我最终还是将页面重写为https或重定向循环。

我错过了一些简单的东西,是错误的顺序吗?我只是不知所措。 谢谢你的帮助。

更新: 以下是我过去的工作原理:

RewriteCond %{HTTPS} on    
RewriteCond %{THE_REQUEST} (\s/products/product1|\s/products/product2|\s/products/product3) [NC]    
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]    


RewriteCond %{HTTPS} off    
RewriteCond %{THE_REQUEST} !\s/products/product1 [NC]    
RewriteCond %{THE_REQUEST} !\s/products/product2 [NC]    
RewriteCond %{THE_REQUEST} !\s/products/product3 [NC]   
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

1 个答案:

答案 0 :(得分:2)

以下是我们如何在网站上使用iframe无法在SSL上运行的网络摄像头实现这一目标。这也是一个ExpressionEngine网站。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#force www instead of non-www
RewriteCond %{HTTP_HOST} ^domain.co.uk
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [R=301,L] 

# HTTP/HTTPS handling 
# Force HTTP for webcam page only
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} \s/webcam-page [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

# Force HTTPS for all pages except webcam
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\s/webcam-page [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]  

# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
相关问题