Apache mod 重写重定向

发布于 2024-10-01 09:32:19 字数 432 浏览 1 评论 0原文

我需要做的:

如果用户访问 test.com 那么服务器必须重定向到 ma​​in.com/check.php,检查某些内容并返回到 test。 com

.htaccess:

RewriteCond %{HTTP_HOST} !^main\.com$ [NC]
RewriteRule ^(.*)$ http://main.com/check.php?url=%{HTTP_HOST}%{REQUEST_URI} [L]

check.php

header("location: http://" . $_GET['url']);

但它正在循环。

有什么想法吗?

I need to do:

if user go to test.com then server must redirect to main.com/check.php, checks something and return back to test.com

.htaccess:

RewriteCond %{HTTP_HOST} !^main\.com$ [NC]
RewriteRule ^(.*)$ http://main.com/check.php?url=%{HTTP_HOST}%{REQUEST_URI} [L]

check.php

header("location: http://" . $_GET['url']);

But it`s looping.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

十六岁半 2024-10-08 09:32:19

最佳选择 我认为您正在寻找的是:使用公共域跨多个域共享会话。如果是这样,请查看此主题:跨域共享会话

确定选项 如果您不喜欢这样,您可以将所有用户的页面视为单独的服务并实施 单点登录系统。

顽固选项 如果这不是您想要的,并且您想坚持使用 mod_rewrite,我所能建议的就是尝试更多的 RewriteCond 来取消循环资格。例如,尝试添加: RewriteCond %{QUERY_STRING} !*some string* [NC, OR] 到 @nerkn 建议的顶部(当然,还要在 check.php 中发送查询字符串)。

Best Option I think what you're looking for is: Using a common domain to share sessions across multiple domains. If so, check out this SO thread: Sharing sessions across domains

OK Option If you don't like that, you may be able to treat all your users' pages as separate services and implement a Single sign on system.

Stubborn Option If that's not what you're looking for and you want to stick with mod_rewrite, all i could suggest is trying more RewriteConds to disqualify the loop. For instance, try adding: RewriteCond %{QUERY_STRING} !*some string* [NC, OR] to the top of @nerkn's suggestion (and of course sending a query string in your check.php.

め可乐爱微笑 2024-10-08 09:32:19

.htaccess 不知道脚本已检查,所以我添加了引荐来源网址。但这是松散的检查,我认为你应该相信其他机制。如果存在危险的话,推荐人信仰也是危险的。

RewriteCond %{HTTP_REFERER} !main\.com [NC, OR]
RewriteCond %{HTTP_HOST} !^main\.com$ [NC]
RewriteRule ^(.*)$ http://main.com/check.php?url=%{HTTP_HOST}%{REQUEST_URI} [L]

.htaccess does not know script has checked, so I added referrer. But it is loose check, I think you should believe other mechanism. Referrer belief is dangerous, if there is danger.

RewriteCond %{HTTP_REFERER} !main\.com [NC, OR]
RewriteCond %{HTTP_HOST} !^main\.com$ [NC]
RewriteRule ^(.*)$ http://main.com/check.php?url=%{HTTP_HOST}%{REQUEST_URI} [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文