.htaccess重定向到https,但管理员url除外 [英] .htaccess redirect to https except admin url

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

问题描述

我想将所有前端请求重定向到安全站点https,并且所有admin/后端url都应保持不安全的http. 另外,我使用Cloudflare CDN.

I would like to redirect all frontend requests to secured site https and all admin / backend urls should remain unsecured http. In addition, I use Cloudflare CDN.

我的重写规则不起作用,所有查询都转到https.

My rewrite rules do not work, all queries go to https.

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{REQUEST_URI} !admin
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301]

请帮助我.

推荐答案

尽管我会更改,但它应该可以正常运行

It should work fine as you have it, although I would change:

RewriteCond %{REQUEST_URI} !admin

也许:

RewriteCond %{REQUEST_URI} !^/admin/

如果它适合您的网址,或者:

If that is suitable for your URLs, or:

RewriteCond %{REQUEST_URI} !^/admin

(如果前端URL的某个位置应包含"admin")

(in case a front-end URL should have 'admin' in it somewhere)

但是无论如何,您可能只是在重定向开始之前在浏览器中缓存了重定向.清除您的缓存或忘记此网站".

But anyway, you probably just have a redirect cached in your browser from before you got it working. Clear you cache or "forget this site".

也删除第二行,无需再次检查.

Also remove line two, no need to check twice.

但是,也不要只通过HTTPS来运行管理员,这只是为了确保登录时的安全性以及传输机密数据的可惜.

But it's a shame not to run your admin over HTTPS too, just for security when logging in to it etc. and transferring confidential data.

更新

由于清除缓存无法解决问题(请参见注释),因此建议启用日志记录.

Since clearing the cache did not fix it (see comments) recommended enabling logging.

更新2

根据评论中的讨论,尝试以下操作:

Based on discussion in comments, try this:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteCond %{REQUEST_URI} !^(/index\.php)?/admin(/|$)
RewriteRule ^ https://example.com%{REQUEST_URI} [L,R=301]

这是因为看起来您的应用程序在生成管理URL时可能正在添加/index.php.因此,这也涵盖了这一点.

This is because it looks like your application may be adding /index.php when it generates admin URLs. So this would cover that too.

这篇关于.htaccess重定向到https,但管理员url除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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