忽略web.config重定向中的顶级域

时间:2018-02-26 15:37:13

标签: redirect url-rewriting web-config

我们在多个顶级域名(例如domain1domain2)中拥有多个域名(例如tld1tld2) ,包括其子域名,目前使用以下规则重定向到domain1.tld1

<rule>
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^domain1\.tld1$" negate="true" />
    </conditions>
    <action type="Redirect" url="http://domain1.tld1/{R:1}" />
</rule>

但是,我们现在希望在重定向时保留顶级域名 - 即:重定向应该是domain1.tld1domain1.tld2,具体取决于输入的原始TLD。经过一番试验和错误和搜索我似乎无法弄明白。这是我最近的尝试,在没有TLD的情况下重定向到domain1.

<rule>
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^domain1\.(.*)$" negate="true" />
    </conditions>
    <action type="Redirect" url="http://domain1.{C:1}/{R:1}" />
</rule>

理想情况下,我们需要一个不会要求我们在获取更多域时添加新的顶级域名的解决方案。因此,如果明天注册domain1.tld3domain2.tld3,则无需编辑web.config文件即可添加tld3

2 个答案:

答案 0 :(得分:1)

Try capturing the TLD in its own condition like so:

<rule>
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^domain1\." negate="true" />
        <add input="{HTTP_HOST}" pattern="^\[\w\d-]+\.(.[\w\d]+)" />
    </conditions>
    <action type="Redirect" url="http://domain1.{C:1}/{R:1}" />
</rule>

答案 1 :(得分:0)

我最终到达那里,部分归功于James' suggestion添加另一个条件:

//this is your camera method
- (void)startCameraControllerUsingDelegate:(id<UIImagePickerControllerDelegate, UINavigationControllerDelegate>)delegate gallery:(BOOL)openGallery
{
    if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO)
        || (delegate == nil))
        return;

    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
    if (openGallery) {
        cameraUI.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    } else {
        cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
    }

    cameraUI.allowsEditing = YES;
    //set your delegate type UINavigationControllerDelegate here! It will trigger function bellow!
    cameraUI.delegate = delegate;

    [self presentViewController:cameraUI animated:YES completion:nil];
}

//UINavigationControllerDelegate function
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //this is where magic happends! This leaves button empty and it will not ruin title center position!... or give it your desired string
    viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}

对子域进行硬编码并不适合我的情况,但它可以完成这项任务。