简体   繁体   English

如何从子域上的文件夹重定向到主域

[英]How do I redirect from a folder on a subdomain to main domain

Bit of additional info... 一点点附加信息...

PHPBB has a way to redirect you after login to the page you were looking at before, even if you're using the login-form externally on your own pages. 即使您在自己的页面上外部使用登录表单,PHPBB也可以在登录后将您重定向到您之前查看的页面。 However they decided it should be a relative path within your own domain. 但是他们决定这应该是您自己域内的相对路径。 Which is not exactly great if you have the forum on a subdomain like forum.mydomain.com... 如果您将论坛放在诸如forum.mydomain.com之类的子域上,那不是很好。

The example from their wiki : <input type="hidden" name="redirect" value="./somefile.html" /> 他们的Wiki中的示例: <input type="hidden" name="redirect" value="./somefile.html" />

To work around the problem of the subdomain, I figured I would add an indication of a frontpage redirect to it, like <input type="hidden" name="redirect" value="./redirect/frontpagenews.php" /> 要变通解决子域的问题,我想我会向其添加首页重定向的指示,例如<input type="hidden" name="redirect" value="./redirect/frontpagenews.php" />

So if you use the login-form on the page http://mysite.com/frontpagenews.php the forum redirect url ends up looking like forum.mysite.com/redirect/frontpagenews.php (this works, the forum creates this link to go back to after login). 因此,如果您使用http://mysite.com/frontpagenews.php页面上的登录表单,则论坛重定向URL最终看起来像forum.mysite.com/redirect/frontpagenews.php (此方法有效,论坛创建了此链接登录后返回)。 All it needs is a rewrite rule to detect this so it would actually sent you back to http://mysite.com/frontpagenews.php 它所需要的只是一个重写规则以检测到该错误,因此它实际上会将您发送回http://mysite.com/frontpagenews.php

The question... 问题...

How do I go from forum.mysite.com/redirect/*anything* to mysite.com/*anything* ? 如何从forum.mysite.com/redirect/*anything*转到mysite.com/*anything*

I've been at this for a while now, and I think the code below should work, except it doesn't. 我已经花了一段时间了,我认为下面的代码应该可以工作,除非不能。 I've put it above the other forum rewrite rules in the htaccess file in forum.mysite.com as it probably should be fine if it's the first rule that's checked. 我已将它放在forum.mysite.com的htaccess文件中的其他论坛重写规则之上,因为如果它是检查的第一个规则,则可能会很好。

RewriteCond %{HTTP_HOST} ^forum\.mysite\.com/redirect/(.*)$ [NC]
RewriteRule (.*) http://mysite\.com/$1 [QSA,L,NC]

Also tried this as condition, but no joy: 也尝试将此作为条件,但没有喜悦:

RewriteCond %{REQUEST_URI} /redirect/(.*)$ [NC]

The HTTP_HOST only matches against a hostname, not the path. HTTP_HOST仅与主机名匹配,而不与路径匹配。 The path needs to be part of the RewriteRule. 该路径必须是RewriteRule的一部分。 Assuming that the .htaccess file that you are editing resides in the forum.mysite.com root (as in the equivalent of: forum.mysite.com/.htaccess), it should look like this: 假设您正在编辑的.htaccess文件位于forum.mysite.com根目录中(等效于:forum.mysite.com/.htaccess),它应如下所示:

RewriteCond %{HTTP_HOST} ^forum\.mysite\.com$ [NC]
RewriteRule ^redirect/(.+)$ http://mysite.com/$1 [L,NC,R]

You won't need the QSA in the rule brackets because the query string will get appended anyways (unless you have a ? in the target, eg http://mysite.com/$1?p=1 ). 您将不需要规则括号中的QSA ,因为无论如何查询字符串都会被追加(除非目标中有? ,例如http://mysite.com/$1?p=1 )。

This will redirect the browser from forum.mysite.com/redirect/*anything* to mysite.com/*anything* 这会将浏览器从forum.mysite.com/redirect/*anything*重定向到mysite.com/*anything*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM