Apache mod 重写重定向
我需要做的:
如果用户访问 test.com 那么服务器必须重定向到 main.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最佳选择 我认为您正在寻找的是:使用公共域跨多个域共享会话。如果是这样,请查看此主题:跨域共享会话
确定选项 如果您不喜欢这样,您可以将所有用户的页面视为单独的服务并实施 单点登录系统。
顽固选项 如果这不是您想要的,并且您想坚持使用 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
RewriteCond
s 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..htaccess 不知道脚本已检查,所以我添加了引荐来源网址。但这是松散的检查,我认为你应该相信其他机制。如果存在危险的话,推荐人信仰也是危险的。
.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.