URL重写规则禁用HTTPS / SSL,除了一些网页 [英] Apache mod_rewrite rules to disable https/ssl except for some pages
问题描述
我有一个网站brosing一些网页时触发HTTPS,我想恢复到HTTP时,不浏览这些网页,这是我的htaccess的:
< IfModule mod_rewrite.c>
RewriteEngine叙述上
#RewriteBase / MyProject的/
#切换WWW preFIX
的RewriteCond%{HTTP_HOST} ^ WWW \。(。*)$ [NC]
重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]
#重定向图标请求传送到正确的favicon.ico
的RewriteCond%{REQUEST_URI}!^ /图标\ .ICO [NC]
的RewriteCond%{} THE_REQUEST图标\。(ICO | PNG | GIF |?JPE G)[NC]
重写规则的HTTP(*)://mysite/favicon.ico [R = 301,L]
#隐藏的根的index.php
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,} \ S(。*)/指数\ .PHP [NC]
重写规则^ /%1 [R = 301,L]
#禁用HTTPS时,没有必要
的RewriteCond%{} HTTPS上
#RewriteCond%{HTTP_REFERER}!^(HTTPS)(。*)$
的RewriteCond%{REQUEST_URI} ^ /!(*)(例外| XYZ | PQR)$ [NC](*)。
(。*)重写规则的http://%{HTTP_HOST}%{REQUEST_URI} [R = 301,L]
#如果一个目录或文件是否存在,直接使用它
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
#否则将其转发到index.php
重写规则。的index.php [L,QSA]
#RewriteRule ^(。*)\ *?$的index.php / $ 1 [L,QSA]
< / IfModule>
如果我称之为的https://主机/网址
重定向工作正常着陆的http://主机/网址
,但如果我叫的https://的主机/异常
,而不是把它当作是我会被重定向到的http://主机的index.php
什么是错?谢谢
更新与解决方案,希望这将是有用的人。
< IfModule mod_rewrite.c>
RewriteEngine叙述上
#RewriteBase / yourbase
#隐藏的根的index.php
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,} \ S(。*)/指数\ .PHP [NC]
重写规则^ /%1 [R = 301,L]
#直通所以当规则环路(HTTPS),重定向到索引不会得到应用
重写规则的index.php $ - [L]
#切换WWW preFIX
的RewriteCond%{HTTP_HOST} ^ WWW \。(。*)$ [NC]
重写规则^ $ HTTP(*)://%1 / $ 1 [R = 301,L]
#重定向图标请求传送到正确的favicon.ico
的RewriteCond%{REQUEST_URI}!^ /图标\ .ICO [NC]
的RewriteCond%{} THE_REQUEST图标\。(ICO | PNG | GIF |?JPE G)[NC]
重写规则(。*)http://liberos.it/favicon.ico [R = 301,L]
#禁用HTTPS时,没有必要(但不直接改写文件的请求)
的RewriteCond%{} HTTPS上
#RewriteCond%{HTTP_REFERER}!^(HTTPS)(。*)$
的RewriteCond%{REQUEST_URI} ^ /(yourpath |另一个/路径)!(。*)$ [NC](*)。
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d [OR]
的RewriteCond%{REQUEST_URI}。
(。*)重写规则的http://%{HTTP_HOST}%{REQUEST_URI} [R = 301,L]
#如果一个目录或文件是否存在,直接使用它,否则将其转发到index.php
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php
#RewriteRule ^(。*)\ *?$的index.php / $ 1 [L,QSA]
< / IfModule>
由于您是通过路由一切的index.php
,你需要的时候创建一个直通所以规则循环,重定向不会得到应用。尝试添加这条规则在您的规则列表的顶部:
重写规则的index.php $ - [L]
I have a website that trigger HTTPS when brosing some pages and I want to revert back to HTTP when not browsing those pages, and this is my htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /myproject/
# toggle www prefix
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# redirect favicon requests to the correct favicon.ico
RewriteCond %{REQUEST_URI} !^/favicon\.ico [NC]
RewriteCond %{THE_REQUEST} favicon\.(ico|png|gif|jpe?g) [NC]
RewriteRule (.*) http://mysite/favicon.ico [R=301,L]
# hide index.php from root
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]
# disable HTTPS when not needed
RewriteCond %{HTTPS} on
#RewriteCond %{HTTP_REFERER} !^(https)(.*)$
RewriteCond %{REQUEST_URI} !^(.*)/(exception|xyz|pqr)(.*)$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php [L,QSA]
#RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
</IfModule>
If I call https://host/url
the redirect works fine landing to http://host/url
, but if I call https://host/exception
instead of leaving it as is I'll be redirected to http://host/index.php
What's wrong? Thanks
UPDATE with solution, hoping it will be useful to someone
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /yourbase
# hide index.php from root
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]
# pass-through so when the rules loop (https), the redirect to index won't get applied
RewriteRule index.php$ - [L]
# toggle www prefix
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# redirect favicon requests to the correct favicon.ico
RewriteCond %{REQUEST_URI} !^/favicon\.ico [NC]
RewriteCond %{THE_REQUEST} favicon\.(ico|png|gif|jpe?g) [NC]
RewriteRule (.*) http://liberos.it/favicon.ico [R=301,L]
# disable HTTPS when not needed (but don't rewrite direct files requests)
RewriteCond %{HTTPS} on
#RewriteCond %{HTTP_REFERER} !^(https)(.*)$
RewriteCond %{REQUEST_URI} !^(.*)/(yourpath|another/path)(.*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_URI} .
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# if a directory or a file exists use it directly, otherwise forward it to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
#RewriteRule ^(.*)\?*$ index.php/$1 [L,QSA]
</IfModule>
Since you are routing everything through index.php
, you need to create a pass-through so when the rules loop, the redirect won't get applied. Try adding this rule at the very top of your list of rules:
RewriteRule index.php$ - [L]
这篇关于URL重写规则禁用HTTPS / SSL,除了一些网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!