配置MODx Revolution以使用http和https [英] Configuring MODx Revolution to work with both http and https

查看:118
本文介绍了配置MODx Revolution以使用http和https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用MODx Revolution的网站(2.2.10-pl,高级安装),我们称之为 www.example.com ,我希望可以使用它http和https。

I have a website using MODx Revolution (2.2.10-pl, advanced install), let's call it www.example.com, which I want to be accessible with both http and https.

实现这一点,我将 site_url 上下文设置调整为 [[++ url_scheme]] www.example.com / 。使用 [[~id]] 创建的链接似乎没问题,但是,有时候,生成的链接真的很奇怪。我的解释是,以编程方式创建链接的代码不适用于我的设置,但我不知道为什么,或者我将如何启用http和https。

to achieve this, I tweaked the site_url context setting to be [[++url_scheme]]www.example.com/. Links created using [[~id]] seem to be alright, however, sometimes, the generated links are really weird. My interpretation is that the code to create links programmatically doesn't work with my settings, but I don't know why, or how else I would go about enabling both http and https.

首先问题,以下示例:如何设置 site_url 或任何其他网站/上下文设置,以便我网站上的链接正常工作同时使用http和https?可选地,根据Revolution的标签评估语义,我看到了一个错误或预期行为的行为吗?

Question first, examples below: How should I set the site_url or any other site/context setting so that links on my site work with both http and https? Optionally, is the behavior I see a bug, or expected behavior given Revolution's tag evaluation semantics?

错误行为示例:

点击管理器中的查看,查找别名示例的资源,打开的地址是

When I click on "View" in the manager for a resource with the alias example, the address that is opened is

https://www.example.com/xyz/[[++url_scheme]]www.example.com/example/

其中 xyz 是我的经理网址。预期的网址当然是

where xyz is my manager URL. The expected URL is of course

https://www.example.com/example/






发生这种情况的另一种情况是登录失败;我的登录电话看起来像这样(减去不相关的部分):


Another case where this happens is for failed logins; my login call looks like this (minus irrelevant parts):

[[!Login? &redirectToOnFailedAuth=`[[++unauthorized_page]]`]]

unauthorized_pa​​ge 预期的完整网址

https://www.example.com/special/401

但为登录失败而打开的网址为 username

but the URL which is opened for a failed login as username is

https://www.example.com/[[++url_scheme]]www.example.com/[[++url_scheme]]www.example.com/special/401?u=username

http的第二个例子是相同的,当然除了方案之外;我没有使用http登录经理。

The second example is the same for http, except for the scheme, of course; I haven't logged into the manager with http.

编辑

.htaccess 在webroot:

RewriteEngine On
RewriteBase /

# redirect all requests to /en/favicon.ico to /favicon.ico
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en)/favicon.ico$ favicon.ico [L,QSA]
#RewriteRule ^(en|nl|de)/favicon.ico$ favicon.ico [L,QSA]

# redirect all requests to /en/assets* /assets*
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(en)/assets(.*)$ assets$2 [L,QSA]
#RewriteRule ^(en|nl|de)/assets(.*)$ assets$2 [L,QSA]

# redirect all other requests to /en/*
# to index.php and set the cultureKey parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
#RewriteRule ^(en|nl|de)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]

.htaccess 在经理目录中:

RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/xyz/$1


推荐答案

问题在于 $ modx-> makeUrl()。例如,对于

[[!Login? &redirectToOnFailedAuth=`[[++unauthorized_page]]`]]

电话,在 core / components / login / controllers / web / Login.php

public function checkForRedirectOnFailedAuth(modProcessorResponse $response) {
    $redirectToOnFailedAuth = $this->getProperty('redirectToOnFailedAuth',false,'isset');
    if ($redirectToOnFailedAuth && $redirectToOnFailedAuth != $this->modx->resource->get('id')) {
        $p = array(
            'u' => $this->dictionary->get('username'),
        );
        $message = $response->getMessage();
        if (!empty($message)) $params['m'] = $message;
        $url = $this->modx->makeUrl($redirectToOnFailedAuth,'',$p,'full');
        $this->modx->sendRedirect($url);
    }
}

最后两行重定向到生成的URL使用 makeUrl ,这将类似于 [[++ url_scheme]] www.example.com/etc 注意:我不是100%肯定在这里,因为我不能轻易查看原始网址。但结论仍然有效。如果URL只显示在页面上,这没有问题,因为MODx会在将标签插入html输出之前对其进行解析。但是,由于URL直接用于重定向,因此不会进行此类替换,并且浏览器会将其解释为相对URL,从而生成目标URL,例如 https://www.example.com/ [[++ url_scheme]] www.example.com/etc

the last two lines do a redirect to a URL generated with makeUrl, which will be something like [[++url_scheme]]www.example.com/etc (note: I'm not 100% sure here, as I can't easily look at the raw URL. The conclusions still hold, though). If the URL is simply shown on the page, this is no problem, because MODx will parse the tag before inserting it into the html output. However, as the URL is used directly for the redirect, no such replacement takes place, and the browser interprets it as a relative URL, resulting in target URLs such as https://www.example.com/[[++url_scheme]]www.example.com/etc.

这个问题太多了。为避免这种情况, site_url 必须是一个没有任何标签的文字值。作为解决方法,我现在使用以下代码段作为我模板中的第一个内容:

So much for the problem. To avoid this, site_url must be a literal value without any tags in it. As a workaround, I now use the following snippet as the first thing in my template:

$modx->config['site_url'] = $modx->config['url_scheme'] . substr($modx->config['site_url'], strlen('[[++url_scheme]]'));
return '';

以及 [[++ site_url]] of

[[++url_scheme]]www.example.com/

请注意,MODx的某些部分似乎没有注意到此更新,这就是为什么仍然使用 [[ ++ url_scheme]] site_url 中。据我所知,没有看到更新的部分,如 [[~id]] ,可以正常使用 url_scheme

Note that some parts of MODx don't seem to notice this update, which is why it's important to still use [[++url_scheme]] in your site_url. As far as I can tell right now, the parts that don't see the update, stuff like [[~id]], work properly with url_scheme.

编辑这当然只修复了经理中的查看按钮,如果你调整了相应的经理模板。

EDIT this does of course only fix the "View" buttons in the manager if you tweak the manager templates accordingly.

警告这当然非常hacky,尚未经过良好测试。某些功能没有看到覆盖值的事实意味着您在网站中引入了不一致,这可能会导致细微的错误!如果出现更干净的解决方案,那就去吧!

WARNING this is of course very hacky, and not yet tested very well. The fact that some features do not see the overwritten value means that you're introducing an inconsistency into your website, which may lead to subtle errors! If a more clean solution comes up, go for it!

这篇关于配置MODx Revolution以使用http和https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆