简体   繁体   English

根据URL重定向到某些页面

[英]Redirect to certain page based on URL

Currently I have set up my websites using Apache the following way: 目前,我已经通过以下方式使用Apache建立了我的网站:

...  
ServerName example-one.com  
ServerAlias example-two.com  
ServerAlias example-three.com  
...

This way they all point to the same directory and open the same index.php file. 这样,它们都指向同一目录并打开相同的index.php文件。
What I want to achieve is to have different landing page for the following but to share the rest of the content. 我想要实现的是在以下内容具有不同的登录页面,但共享其余内容。

My question is now if it's possible to append either some GET parameter like index.php?URL=1 etc. 我的问题是现在是否可以附加一些GET参数,例如index.php?URL = 1等。
Or is there a better way of achieving this? 还是有更好的方法来实现这一目标? Maybe using mod_rewrite? 也许使用mod_rewrite?

What would you do? 你会怎么做?

What you could do is simply load the same template and depending on the URL that is loaded you modify whatever you wish to modify. 您可以做的就是简单地加载相同的模板,然后根据所加载的URL修改您想要修改的内容。 It'd be something like this in pseudo-PHP-code: 在伪PHP代码中可能是这样的:

$site = $_SERVER['SERVER_NAME'];

switch ($site) {
    case 'example-one.com' : {
        loadTemplate('page.html', ['site' => 1]);
    }
    case 'example-two.com' : {
        loadTemplate('page.html', ['site' => 2]);
    }
    case 'example-three.com' : {
        loadTemplate('page.html', ['site' => 3]);
    }
}
<html>
    <head>
        [...]
    </head>
    <body>
        <p>
        <?php
            switch (site) {
                case 1: {
                    echo "hello";
                    break;
                }
                case 2: {
                    echo "goodbye";
                    break;
                }
                case 3: {
                    echo "later";
                    break;
                }
            }
        ?>
        </p>
    </body>
</html>

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

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